private void Confirm(转关箱排车暂存组 暂存组, bool 是否确认) { Dictionary <int, string[]> dict = new Dictionary <int, string[]>(); foreach (Xceed.Grid.DataRow row in m_待排转关箱任务区Grid.DataRows) { System.Data.DataRowView rowView = row.Tag as System.Data.DataRowView; string s = rowView["序号"].ToString(); string[] ss = s.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int idx = ConvertHelper.ToInt(ss[0]).Value; s = rowView["任务号"].ToString(); ss = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); dict[idx] = ss; } Dictionary <int, int> dictIdx = new Dictionary <int, int>(); foreach (var i in dict.Keys) { dictIdx[i] = 0; } using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository <转关箱排车暂存组>()) { try { rep.BeginTransaction(); rep.Attach(暂存组); 暂存组.IsActive = 是否确认 ? true : false; 暂存组.预排时间 = System.DateTime.Now; m_dao暂存组.Update(rep, 暂存组); if (暂存组.转关箱排车 != null) { foreach (var i in 暂存组.转关箱排车) { m_dao.Delete(rep, i); } 暂存组.转关箱排车.Clear(); } else { 暂存组.转关箱排车 = new List <转关箱排车计划>(); } foreach (Xceed.Grid.DataRow row in m_全部监管车辆及作业现状Grid.DataRows) { for (int i = 1; i <= Days; ++i) { string fieldName = string.Format("第{0}天", i); if (row.Cells[fieldName].Value != null) { int idx = ConvertHelper.ToInt(row.Cells[fieldName].Value).Value; System.Diagnostics.Debug.Assert(dict.ContainsKey(idx), "必须在现有待排任务中!"); string rwh = dict[idx][dictIdx[idx]]; dictIdx[idx] = dictIdx[idx] + 1; 转关箱排车计划 entity = new 转关箱排车计划(); entity.车辆 = row.Tag as 车辆; entity.任务号 = rwh; entity.日期 = 是否确认 ? (DateTime?)System.DateTime.Today.AddDays(i) : null; entity.天数序号 = i; entity.暂存组 = 暂存组; m_dao.Save(rep, entity); 暂存组.转关箱排车.Add(entity); } } } rep.CommitTransaction(); } catch (Exception ex) { rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } }
private void Confirm(转关箱排车暂存组 暂存组, bool 是否确认) { Dictionary<int, string[]> dict = new Dictionary<int, string[]>(); foreach (Xceed.Grid.DataRow row in m_待排转关箱任务区Grid.DataRows) { System.Data.DataRowView rowView = row.Tag as System.Data.DataRowView; string s = rowView["序号"].ToString(); string[] ss = s.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); int idx = ConvertHelper.ToInt(ss[0]).Value; s = rowView["任务号"].ToString(); ss = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); dict[idx] = ss; } Dictionary<int, int> dictIdx = new Dictionary<int, int>(); foreach (var i in dict.Keys) { dictIdx[i] = 0; } using (IRepository rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository<转关箱排车暂存组>()) { try { rep.BeginTransaction(); rep.Attach(暂存组); 暂存组.IsActive = 是否确认 ? true : false; 暂存组.预排时间 = System.DateTime.Now; m_dao暂存组.Update(rep, 暂存组); if (暂存组.转关箱排车 != null) { foreach (var i in 暂存组.转关箱排车) { m_dao.Delete(rep, i); } 暂存组.转关箱排车.Clear(); } else { 暂存组.转关箱排车 = new List<转关箱排车计划>(); } foreach (Xceed.Grid.DataRow row in m_全部监管车辆及作业现状Grid.DataRows) { for (int i = 1; i <= Days; ++i) { string fieldName = string.Format("第{0}天", i); if (row.Cells[fieldName].Value != null) { int idx = ConvertHelper.ToInt(row.Cells[fieldName].Value).Value; System.Diagnostics.Debug.Assert(dict.ContainsKey(idx), "必须在现有待排任务中!"); string rwh = dict[idx][dictIdx[idx]]; dictIdx[idx] = dictIdx[idx] + 1; 转关箱排车计划 entity = new 转关箱排车计划(); entity.车辆 = row.Tag as 车辆; entity.任务号 = rwh; entity.日期 = 是否确认 ? (DateTime?)System.DateTime.Today.AddDays(i) : null; entity.天数序号 = i; entity.暂存组 = 暂存组; m_dao.Save(rep, entity); 暂存组.转关箱排车.Add(entity); } } } rep.CommitTransaction(); } catch (Exception ex) { rep.RollbackTransaction(); ExceptionProcess.ProcessWithNotify(ex); } } }