
乐秀生成/状态更新代码如下:
string[] ids = new string[3];
int num = 60;//图片总数
int count = 0;//选中的图片总数
int currentcount = 0;//当前总数
int rand = (new Random()).Next(1, 60);
//计算选中的图片总数
for (int i = 0; i < num; i++)
if (i % rand == 1)
count++;
//生成
for (int i = 0; i < num; i++)
{
if (i % rand == 1)
{
ids[currentcount % 3] = i + "";
currentcount++;
if (currentcount % 3 == 0 || (currentcount % 3 != 0 && currentcount == count))
{
//生成...
string sql = "Update LX_ResTB SET [Status]=1 Where [Id] in(" + string.Join(",", ids) + ")";
textBox1.Text += sql + "\r\n";
//更新状态...
}
}
}编辑反馈,有时状态更新不成功!测试后发现:当count的值小于3时,会构造出错误的sql语句(Update LX_ResTB SET [Status]=1 Where [Id] in(1624,1623,)),因而无法成功更新状态。
修改后的代码:
string[] ids = new string[3] [color=Red]{ "0", "0", "0" }[/color];
int num = 60;//图片总数
int count = 0;//选中的图片总数
int currentcount = 0;//当前总数
int rand = (new Random()).Next(1, 60);
//计算选中的图片总数
for (int i = 0; i < num; i++)
if (i % rand == 1)
count++;
//生成
for (int i = 0; i < num; i++)
{
if (i % rand == 1)
{
ids[currentcount % 3] = i + "";
currentcount++;
if (currentcount % 3 == 0 || (currentcount % 3 != 0 && currentcount == count))
{
//生成...
string sql = "Update LX_ResTB SET [Status]=1 Where [Id] in(" + string.Join(",", ids) + ")";
textBox1.Text += sql + "\r\n";
//更新状态...
}
}
}
评论(0)
暂无评论。