List results = new List();
if (table == null || table.Rows.Count == 0)
return results;
#region 循环外变量声明处
Mixinfo element = new Mixinfo(table.Rows[0]); //记录对象
int flowno = element.FlowNo, //流程号
mixno = element.MixNo, //混料单号
count = 0, //已保存的记录数量
totalp = 0, //上个循环的总吨数向下取整
total = 0, //当前循环的总吨数向下取整
increase = 0; //当前循环增加的整数吨
string claimer1 = element.Claimer_First.ClaimerCode, claimer2 = element.Claimer_Last.ClaimerCode; //两台大机代码
double accumu1 = 0, accumu2 = 0, //上个循环中两台大机累积量
accumu_inton1 = 0, accumu_inton2 = 0, //在上个整吨中两台大机所占的累积量
diff1 = 0, diff2 = 0, //上个循环中两台大机的比例差值
accumu_offset1 = element.Claimer_First.Accumulation, //先启动大机累积量的校准值(当起始累积量不为零时)
accumu_offset2 = element.Claimer_Last.Accumulation; //后启动大机累积量的校准值(当起始累积量不为零时)
List col = new List(); //每个循环的sql语句集合
#endregion
Console.WriteLine(string.Format("待转换记录条数:{0},大机1 {1},大机2 {2}", table == null ? 0 : table.Rows.Count, claimer1, claimer2));
foreach (DataRow dataRow in table.Rows)
{
col.Clear();
totalp = results.Count; //已计算出的吨数
#region 循环内变量声明处
Mixinfo info = new Mixinfo(dataRow);
ReclaimerLite first = info.Claimer_First, last = info.Claimer_Last;
double delta1 = first.Accumulation - accumu1, delta2 = last.Accumulation - accumu2; //两台大机累积量的变化
//假如累积量降低,修正校准值(达到计算纯增长量的作用)
if (delta1 < 0)
accumu_offset1 += delta1;
if (delta2 < 0)
accumu_offset2 += delta2;
//对两台大机的累积量进行校准
first.Accumulation -= accumu_offset1;
last.Accumulation -= accumu_offset2;
double accumut = first.Accumulation + last.Accumulation, //两台大机的总累计吨数
acadded1 = first.Accumulation - accumu1, acadded2 = last.Accumulation - accumu2, //两台大机增加的累积量
//TODO 当大机增加吨数为0时如何计算每吨比例差值
diffa1 = first.Accumulation == accumu1 ? 0 : (first.Diff - diff1) / acadded1, //先起大机每整吨的平均比例差值
diffa2 = last.Accumulation == accumu2 ? 0 : (last.Diff - diff2) / acadded2; //后起大机每整吨的平均比例差值
total = (int)accumut; //目前已有的吨数(整吨)
increase = total - totalp; //本循环增加的整吨数(自上个整吨数增加的累积量向下取整)
double increase_real = accumut - totalp; //当前循环自上个整吨后增加的吨数
double acintonadded_mean1 = (first.Accumulation - accumu_inton1) / increase_real, acintonadded_mean2 = (last.Accumulation - accumu_inton2) / increase_real;
string time = first.TimeString; //时间为主机该条数据的保存时间
#endregion
Console.WriteLine("NO.{0} 流程号:{1},总吨:{2},吨1:{3},吨2:{4},差1:{5},差2:{6},时间:{7}", Mixinfo.Counter++, flowno, total, first.Accumulation, last.Accumulation, first.Diff, last.Diff, time);
for (int i = 1; i <= increase; i++)
{
accumu_inton1 += acintonadded_mean1;
accumu_inton2 += acintonadded_mean2;
string sqlString = string.Format(@"insert into
{13} (flowno, mixno, total, claimer1, prop1, accumu1, diff1, claimer2, prop2, accumu2, diff2, savetime, workid) values ({0}, {1}, {2}, '{3}', {4}, {5}, {6}, '{7}', {8}, {9}, {10}, to_date('{11}', 'yyyy-mm-dd hh24:mi:ss'), '{12}')", flowno, mixno, i + totalp, claimer1, first.Proportion, accumu_inton1, diffa1, claimer2, last.Proportion, accumu_inton2, diffa2, time, info.WorkId, Base.StatTable);
col.Add(sqlString);
results.Add(sqlString);
//count += Base.DataService.Provider.ExecuteSql(sqlString);
}
if (Base.DataService.Provider.ExecuteSqlTrans(col))
count += col.Count;
Console.WriteLine("已保存:{0}", count);
accumu1 = first.Accumulation;
accumu2 = last.Accumulation;
diff1 = first.Diff;
diff2 = last.Diff;
}
Console.WriteLine(string.Format("吨数:{0},保存记录条数:{1}", total, count));