/// <summary> /// 20180115 服务器端获得最新的出焦、装煤计划 /// </summary> private void PushAndStokingPlan() { TPushPlan p = new TPushPlan(OPC.Server.TRoomNum, 1, 1, OPC.Server.PushTime); MStokingPlan s = new MStokingPlan(OPC.Server.MRoomNum, OPC.Server.StokingTime, 1, 1); if (CokeRoom.PushPlan.Count == 0) { CokeRoom.PushPlan.Add(p); } else { bool flag = CokeRoom.PushPlan[0].RoomNum != p.RoomNum; if (flag) { CokeRoom.PushPlan.RemoveAt(0); CokeRoom.PushPlan.Add(p); } } if (CokeRoom.StokingPlan.Count == 0) { CokeRoom.StokingPlan.Add(s); } else { bool flag = CokeRoom.StokingPlan[0].RoomNum != s.RoomNum; if (flag) { CokeRoom.StokingPlan.RemoveAt(0); CokeRoom.StokingPlan.Add(s); } } }
public void AddToDbPlan(List <TPushPlan> plan) { if (plan == null || plan.Count == 0) { return; } List <PushPlan> lstPlan = new List <PushPlan>(); DateTime wrtTime = DateTime.Now; for (int i = 0; i < plan.Count; i++) { TPushPlan p = plan[i]; lstPlan.Add(new PushPlan { 炉号 = p.RoomNum, 预定出焦时间 = p.PushTime, 次装煤时间 = p.StokingTime, 计划结焦时间 = (short)p.BurnTime, 规定结焦时间 = (short)p.StandardBurnTime, 时段 = (byte)p.Period, 班组 = (byte)p.Group, 计划写入时间 = wrtTime }); } db.PushPlan.InsertAllOnSubmit(lstPlan); }
/// <summary> /// 删除计划(isEditing==false时,更改Config文件的Attribute:Valid的值) /// </summary> /// <param name="lst">DataGrid.SelectedItems</param> /// <param name="plan">editingPlan或CokeRoom.PushPlan</param> /// <param name="isEditing">是否处于编辑计划状态</param> /// <returns>ItemsSource</returns> public static void DeleteTPlan(IList lst, List <TPushPlan> plan, bool isEditing, int area) { //删除计划分为编辑计划时删除和非编辑状态时删除 //编辑计划时删除计划,只删除editingPlan //非编辑计划时删除计划,需删除CokeRoom.PushPlan和Config文件中的信息,Valid置0; IList editItems = lst; if (lst != null && lst.Count > 0) { //List<TPushPlan> lstPlan = new List<TPushPlan>(); for (int i = 0; i < editItems.Count; i++) { TPushPlan p = editItems[i] as TPushPlan; int index = plan.FindIndex(x => x.RoomNum == p.RoomNum); if (index >= 0) { plan.RemoveAt(index); } } if (!isEditing) { //非编辑状态下,推焦计划更新至Config文件:RoomPlanInfo.config; string path = @"Config\RoomPlanInfo.config"; OperateConfig config = new OperateConfig(path); for (int i = 0; i < editItems.Count; i++) { TPushPlan p = editItems[i] as TPushPlan; //非编辑计划时,要更新Config中的Attribute--valid的值 config.SetPlanAttributeValue(p.RoomNum, "Valid", "0"); } config.XmlDoc.Save(config.Path); plan.Sort(TPushPlan.CompareByTime); } } }
/// <summary> /// 根据推掉的炉号来更新PushPlan、StokingPlan和Config /// </summary> private void JobCarDealPushPlan() { OperateConfig config = new OperateConfig(@"Config\RoomPlanInfo.config"); if (PushPlanIndex >= 0) { if (RoomNum != CokeRoom.PushPlan[PushPlanIndex].RoomNum) { PushPlanIndex = GetIndexOfPushPlan(); //20171212 交叉作业:两辆车同时推焦时,计划索引有可能发生变化; } for (int i = 0; i < PushPlanIndex + 1; i++) { TPushPlan p = CokeRoom.PushPlan[i]; int room = p.RoomNum; config.XmlNodeList[room - 1].Attributes["PushTime"].Value = PushTime; config.SetPlanAttributeValue(RoomNum, "Valid", "0"); } CokeRoom.PushPlan.RemoveRange(0, PushPlanIndex + 1); } else { int room = RoomNum; config.XmlNodeList[room - 1].Attributes["PushTime"].Value = PushTime; config.SetPlanAttributeValue(RoomNum, "Valid", "0"); } config.Save(); }
/// <summary> /// 先得到,由输入的第一炉计划生成当前时段的计划 /// </summary> /// <param name="plan"></param> private void GeneratePlanBy(TPushPlan plan) { if (editingTPlan.Count == 0) { editingTPlan.Add(plan); } for (int i = 0; i < 110; i++) { TPushPlan pGenerate = new TPushPlan(); pGenerate.PushTime = editingTPlan.Last().PushTime.AddMinutes(BreakTime); //bool right = IsTimeRight(cboPeriod.SelectedIndex, pGenerate.PushTime); //下一炉的出焦时间超过时段规定则跳出生成 if (!IsTimeRight(cboPeriod.SelectedIndex, pGenerate.PushTime)) { break; } bool area = cboArea.SelectedIndex <= 0;//炉区 pGenerate.RoomNum = GetNextRoomNum(editingTPlan.Last().RoomNum); pGenerate.Group = plan.Group; pGenerate.Period = plan.Period; pGenerate.StokingTime = CokeRoom.BurnStatus[pGenerate.RoomNum].StokingTime; //DateTime stokingTime = (area ? CokeRoom.BurnStatus12 : CokeRoom.BurnStatus34)[pGenerate.RoomNum].StokingTime; pGenerate.BurnTime = (int)(pGenerate.PushTime - pGenerate.StokingTime).TotalMinutes; editingTPlan.Add(pGenerate); } editingTPlan.Sort(TPushPlan.CompareByTime); }
/// <summary> /// /// </summary> /// <param name="index"></param> /// <param name="pushTime"> 开始推焦时间</param> /// <param name="tjc">是否为工作车</param> public PsInfo(int index, string pushTime, Tjc tjc) { List <Vehicle> lstVehical = tjc.JobCar ? Communication.TJobCarLst : Communication.NonJobCarLst; bool valid = index >= 0 ? true : false; DateTime invalidTime = Convert.ToDateTime("2012-04-03 13:14"); TPushPlan pNull = new TPushPlan(1, 1, 1, invalidTime); TPushPlan p = new TPushPlan(); p = valid ? CokeRoom.PushPlan[index] : (CokeRoom.PushPlan.Count > 0 ? new TPushPlan(CokeRoom.PushPlan[0]) : pNull); //20170923 PushPlan.Count==0时如何处理? PlanRoom = p.RoomNum; //计划炉号 ActualRoom = (byte)tjc.RoomNum; //pInfo.实际炉号 = (byte)lst[0].RoomNum; //pInfo.实际推焦时间 = Convert.ToDateTime(now); ActualPushTime = Convert.ToDateTime(pushTime); //pInfo.预定出焦时间 = p.PushTime; PlanPushTime = p.PushTime; //pInfo.上次装煤时间 = p.StokingTime;//默认值 LastStokingTime = p.StokingTime; //pInfo.规定结焦时间 = p.standardBurnTime; StandardBurnTime = p.StandardBurnTime; //pInfo.计划结焦时间 = p.BurnTime; PlanBurnTime = p.BurnTime; //pInfo.实际结焦时间 = (int)(Convert.ToDateTime(now) - p.StokingTime).TotalMinutes; ActualBurnTime = (int)(Convert.ToDateTime(pushTime) - p.StokingTime).TotalMinutes; //pInfo.时段 = (byte)p.Period; Period = (byte)p.Period; //pInfo.班组 = (byte)p.Group; Group = (byte)p.Group; DwTogetherInfo tInfo = tjc.JobCar ? Communication.JobCarTogetherInfo : Communication.NonJobCarTogetherInfo; //pInfo.Push联锁信息 = tInfo.InfoToInt; LockInfo = tInfo.InfoToInt; //pInfo.联锁 = tInfo.PushTogether ? (byte?)1 : 0; Lock = (byte)(tInfo.PushTogether ? 1 : 0); //pInfo.Push工作车序列 = (short)(lst[0].CarNum * 100 + lst[1].CarNum * 10 + lst[2].CarNum); Cars = (short)(lstVehical[0].CarNum * 100 + lstVehical[1].CarNum * 10 + lstVehical[2].CarNum); //推拦熄煤箭头:20170601 暂设置为固定值16;当工作推焦车出焦时,有三工作车得到箭头;非工作车时,置零 //pInfo.Push对中序列 = null; CarsReady = ArrowsToInt(lstVehical[0].Arrows, lstVehical[1].Arrows, lstVehical[2].Arrows);//箭头指示:前四位bit为推焦车的箭头,接下来四位拦焦车箭头,最后四位熄焦车箭头;共占12bit //pInfo.Push推焦车地址 = lst[0].DataRead.PhysicalAddr; TAddr = lstVehical[0].DataRead.PhysicalAddr; //pInfo.Push拦焦车地址 = lst[1].DataRead.PhysicalAddr; LAddr = lstVehical[1].DataRead.PhysicalAddr; //pInfo.Push熄焦车地址 = lst[2].DataRead.PhysicalAddr; XAddr = lstVehical[2].DataRead.PhysicalAddr; //pInfo.Push推焦车炉号 = lst[0].RoomNum; TRoom = lstVehical[0].RoomNum; //pInfo.Push拦焦车炉号 = lst[1].RoomNum; LRoom = lstVehical[1].RoomNum; //pInfo.Push熄焦车炉号 = lst[2].RoomNum; XRoom = lstVehical[2].RoomNum; //pInfo.Push车辆通讯状态 = null;//20170601 通讯状态暂未处理;设备的顺序:PLC,触摸屏,无线模块,解码器,每辆车占4bit,共计8辆车, CommStatus = 0;//20170601 通讯状态暂未处理 PlanIndex = index; PlanCount = CokeRoom.PushPlan.Count; BeginTime = DateTime.Now; RecAddr(); }
public static TPushPlan UpdateEditingPlan(int roomNum, int period, int group, DateTime dt) { TPushPlan plan = new TPushPlan(); plan.RoomNum = (byte)roomNum; plan.Period = period; plan.Group = group; plan.PushTime = dt; return(plan); }
public void IniValue(TPushPlan plan, int burnTime) { RoomNum = plan.RoomNum; PlanToPushTime = plan.PushTime; StokingTime = plan.StokingTime; PlanBurnTime = plan.BurnTime; StandardBurnTime = burnTime; Period = plan.Period; Group = plan.Group; }
/// <summary> /// 打开Excel表格,预览后打印 /// </summary> /// <param name="plan"></param> private void PrintNotDirect(TPushPlan plan) { string filePath = "..\\..\\PushPlan.xlsx"; string mesg = "即将打印的计划为:" + plan.StrPeriod + "," + plan.StrGroup + "," + cboPrintArea.SelectionBoxItem.ToString() + ";\n稍后3s中打开Excel表格,预览后手动打印!"; if (MessageBoxResult.Yes == MessageBox.Show(mesg, "提示", MessageBoxButton.YesNo)) { System.Diagnostics.Process.Start(filePath);//打开EXCEL表格 } }
private List <ushort> PlanTime() { //时间格式为 dd-HH-mm,2017-11-12 13-14--> 121314; List <ushort> s = new List <ushort>(); TPushPlan t = PushPlan; string tTime = t.PushTime.Day.ToString("00") + t.PushTime.Hour.ToString("00") + t.PushTime.Minute.ToString("00"); MStokingPlan m = StokingPlan; string mTime = m.StokingTime.Day.ToString("00") + m.StokingTime.Hour.ToString("00") + m.StokingTime.Minute.ToString("00"); s.AddRange(IntToUShortArr(Convert.ToInt32(tTime)));//推计划时间 s.AddRange(IntToUShortArr(Convert.ToInt32(mTime))); return(s); }
/// <summary> /// 删改装煤计划 /// </summary> /// <param name="lst">DataGrid.SelectedItems</param> /// <param name="mPlan">装煤计划(editingMPlan或CokeRoom.StokingPlan)</param> /// <returns></returns> public static void DeleteMplan(IList lst, List <MStokingPlan> mPlan) {// mPlan是引用类型,在方法里的操作等同于在使用位置的操作 IList mLst = lst; for (int i = 0; i < mLst.Count; i++) { TPushPlan p = mLst[i] as TPushPlan; int index = mPlan.FindIndex(x => x.RoomNum == p.RoomNum); if (index >= 0) { mPlan.RemoveAt(index); } } mPlan.Sort(MStokingPlan.CompareByTime); }
/// <summary> /// 第一炉计划,并显示在TextBox中 /// </summary> /// <param name="area"></param> /// <param name="period"></param> /// <param name="group"></param> /// <param name="date"></param> /// <returns></returns> private TPushPlan SetFirstPlan(byte roomNum, DateTime time) { try { TPushPlan p = new TPushPlan(); p.Group = cboGroup.SelectedIndex; p.Period = cboPeriod.SelectedIndex; p.RoomNum = roomNum; p.PushTime = time; p.BurnTime = p.GetBurnTime(); return(p); } catch (Exception) { return(null); } }
/// <summary> /// 修改推焦时间(结焦时间) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdatePushTime_Click(object sender, RoutedEventArgs e) { if (cboPeriod.SelectedIndex == 0) { MessageBox.Show("修改出焦时间必须指定时段:白班or夜班!"); return; } if (!isEditing) { MessageBox.Show("计划已保存,不允许修改检修时间!如果需要修改,请先删除当前时段计划!"); return; } Button btn = sender as Button; if (btn != null && isEditing) { int count = dgEdit.SelectedItems.Count; if (count > 1 || count == 0) { MessageBox.Show("修改检修时间时,请选定起始待修改炉号所在行(单行),输入检修时间!"); return; } int min; int.TryParse(txtUpdateTime.Text, out min);//得到检修时间的值 TPushPlan p = dgEdit.SelectedItem as TPushPlan; int index = editingTPlan.FindIndex(x => x.RoomNum == p.RoomNum); int timespan = index > 0 ? ((int)(editingTPlan[index].PushTime - editingTPlan[index - 1].PushTime).TotalMinutes) : 0; int addTime = ((string)btn.Tag) == "0" ? (min - timespan) : ((string)btn.Tag == "1" ? min : -min); int planCount = editingTPlan.Count; for (int i = index; i < planCount; i++) { editingTPlan[i].PushTime = editingTPlan[i].PushTime.AddMinutes(addTime); editingTPlan[i].BurnTime = editingTPlan[i].BurnTime + addTime; if (!IsTimeRight(cboPeriod.SelectedIndex, editingTPlan[i].PushTime)) {//RemoveRange方法的Count参数:例 plan.count=9,maxIndex=8,i=5时,包括index=5的count共有9-1-5+1个; editingTPlan.RemoveRange(i, planCount - (i + 1) + 1); break; } } int dgIndex = dgEdit.SelectedIndex; dgEdit.ItemsSource = null; dgEdit.ItemsSource = editingTPlan; dgEdit.SelectedIndex = dgIndex;//用于修改完检修时间后,使该条仍被选中 } }
public Communication() { //加载错误日志记录帮助,20170924 Log.LogSys.Info("启动时间:" + DateTime.Now.ToString("g")); CommLst = new List <CommExamine>(); UITime = new SysTime(); //初始地址字典,对应炉号的各生产时间 Room = new CokeRoom(); PushPlan = new TPushPlan(); StokingPlan = new MStokingPlan(); //开启TCP/IP通讯;20180115 服务器端不用开启 if (!Setting.IsServer) { CommHelper = new SocketHelper(); CommHelper.StartListening(); } OPCInfo = new OPC(); //初始化8辆车 InitCars(); IniTogetherInfo(); //得到工作车的联锁信息 GetCarTogetherInfo(JobCarTogetherInfo, true); GetMTogetherInfo(MJobCarTogetherInfo, true); //得到非工作车的联锁信息******** GetCarTogetherInfo(NonJobCarTogetherInfo, false); GetMTogetherInfo(MNonJobCarTogetherInfo, false); DataWrite = new DataWrite(); CommStatus = new List <CommStatus>(); IniTimer(); if (Setting.IsServer) { PushAndStokingPlan(); //20180115 服务器端处理计划推焦和计划装煤炉号 } //测试用方法 正式编译前应注释掉 20171021 //_BindingTest(); }
private void btnInsert_Click(object sender, RoutedEventArgs e) { #region dpPlan中连续选择多条乱笺号的处理 //if (!isEditing) //{ // MessageBox.Show("当前计划已保存,不允许修改!如有修改必要,请删除当前计划后重新编辑计划!"); // return; //} //if (dgPlan.SelectedItems.Count <= 0) //{ // MessageBox.Show("请选择乱笺炉号!"); // return; //} //int time; //try //{ // time = Convert.ToInt32(txtInsertPushTime.Text); //} //catch (Exception) //{ // MessageBox.Show("请检查输入的时间是否正确"); // return; //} ////准备乱笺的炉号和时间 ////dgPlan.ItemsSource = null; //IList lst = dgPlan.SelectedItems; //List<TPushPlan> lstPlan = new List<TPushPlan>(); //for (int i = 0; i < lst.Count; i++) //{ // TPushPlan a = lst[i] as TPushPlan; // lstPlan.Add(a); //} //for (int i = 0; i < lstPlan.Count; i++) //{ // lstPlan[i].BurnTime = lstPlan[i].BurnTime + time; // lstPlan[i].PushTime = lstPlan[i].PushTime.AddMinutes(time); //} //lstPlan.Sort(TPushPlan.CompareByTime); //int fstIndex = editingTPlan.FindIndex(x => x.RoomNum == lstPlan[0].RoomNum); //editingTPlan.RemoveRange(fstIndex, lstPlan.Count); ////editingTPlan lstPlan ////afterCount:乱笺号未后移之前,editingTPlan中 选择乱笺号后 后部分的计划条目数 //int count = editingTPlan.Count; //editingTPlan[fstIndex].PushTime = lstPlan[0].PushTime.AddMinutes(-time); //editingTPlan[fstIndex].BurnTime = editingTPlan[fstIndex].GetBurnTime(); //for (int index = fstIndex + 1; index < count; index++) //{ // TPushPlan p = editingTPlan[index]; // if (p.PushTime < lstPlan.Last().PushTime) // { // p.PushTime = editingTPlan[index - 1].PushTime.AddMinutes(9); // p.BurnTime = p.GetBurnTime(); // } // if (p.PushTime >= lstPlan.Last().PushTime) // { // p.PushTime = lstPlan.Last().PushTime.AddMinutes(9); // p.BurnTime = p.GetBurnTime(); // if (index + 1 >= count) break; // for (int j = index + 1; j < count; j++) // { // //if (j >= afterCount) break; // TPushPlan p1 = editingTPlan[j - 1]; // editingTPlan[j].PushTime = p1.PushTime.AddMinutes(9); // editingTPlan[j].BurnTime = editingTPlan[j].GetBurnTime(); // if (!IsTimeRight(cboPeriod.SelectedIndex, editingTPlan[j].PushTime)) // { // editingTPlan.RemoveRange(j, count - j); // break; // } // } // break; // } //} //editingTPlan.AddRange(lstPlan); //editingTPlan.Sort(TPushPlan.CompareByTime); //dgPlan.ItemsSource = null; //dgPlan.ItemsSource = editingTPlan; #endregion #region 2017-07-24修改乱笺号逻辑 //if (!isEditing) //{ // MessageBox.Show("非计划编辑时,禁止修改乱笺号!"); // return; //} //TPushPlan p = new TPushPlan(); //p.RoomNum = (byte)InsertRoomNum; //p.PushTime = (DateTime)InsertPushTime; //p.Group = editingTPlan[0].Group; //p.Period = editingTPlan[0].Period; //p.BurnTime = p.GetBurnTime(); //int index = editingTPlan.FindIndex(x => x.RoomNum == InsertRoomNum); //if (index < 0) //{ // editingTPlan.Add(p); //} //else //{ // //p.PushTime>editingTPlan[index].PushTime // List<TPushPlan> lstP1 = new List<TPushPlan>(); // lstP1.Add(editingTPlan[index]); // editingTPlan.RemoveAt(index); // if (p.PushTime > lstP1[0].PushTime) // { // for (int i = index; i < editingTPlan.Count; i++) // { // editingTPlan[i].PushTime = i == index ? lstP1.Last().PushTime : editingTPlan[i - 1].PushTime; // if (editingTPlan[i].PushTime >= p.PushTime) // { // for (int j = i; j < editingTPlan.Count; j++) // { // editingTPlan[j].PushTime = j == i ? p.PushTime.AddMinutes(9) : editingTPlan[j - 1].PushTime.AddMinutes(9); // if (!IsTimeRight(cboPeriod.SelectedIndex, editingTPlan[j].PushTime)) // { // editingTPlan.RemoveRange(j, editingTPlan.Count - j); // break; // } // editingTPlan[j].BurnTime = editingTPlan[j].GetBurnTime(); // } // break; // } // editingTPlan[i].BurnTime = editingTPlan[i].GetBurnTime(); // } // } // else // {//p.PushTime<lstP1[0].PushTime时,index>0; // for (int i = index - 1; i >= 0; i--) // { // editingTPlan[i].PushTime = i == (index - 1) ? lstP1[0].PushTime : editingTPlan[i + 1].PushTime.AddMinutes(-9); // if (editingTPlan[i].PushTime <= p.PushTime) // { // for (int j = i; j >= 0; j--) // { // editingTPlan[j].PushTime = j == i ? p.PushTime.AddMinutes(-9) : editingTPlan[j + 1].PushTime.AddMinutes(-9); // editingTPlan[j].BurnTime = editingTPlan[j].GetBurnTime(); // } // break; // } // editingTPlan[i].BurnTime = editingTPlan[i].GetBurnTime(); // } // } // editingTPlan.Add(p); // editingTPlan.Sort(TPushPlan.CompareByTime); //} //txtInsertRoom.Text = (cboArea.SelectedIndex == 0 ? GetNextRoomInfo12(InsertRoomNum) : GetNextRoomInfo34(InsertRoomNum)).ToString("000"); //txtInsertPushTime.Text = InsertPushTime.Value.AddMinutes(9).ToString("t"); //dgPlan.ItemsSource = null; //dgPlan.ItemsSource = editingTPlan; #endregion if (!isEditing) { MessageBox.Show("当前计划已保存,不允许修改!如有修改必要,请删除当前计划后重新编辑计划!"); return; } //准备乱笺的炉号和时间 int room = GetInputRoomNum(txtInsertRoom.Text); DateTime time = GetInputDateTime(txtInsertPushTime.Text, dpDate.SelectedDate); if (room == -1 || time.Year == 1988) { MessageBox.Show("乱笺号的出焦炉号或出焦时间输入有误,请检查后继续操作!"); return; } TPushPlan p = new TPushPlan(room, cboPeriod.SelectedIndex, cboGroup.SelectedIndex, time); int index = editingTPlan.FindIndex(x => x.RoomNum == p.RoomNum); if (index >= 0) { editingTPlan.RemoveAt(index); } editingTPlan.Add(p); editingTPlan.Sort(TPushPlan.CompareByTime); int insertIndex = editingTPlan.FindIndex(x => x.RoomNum == p.RoomNum); //insertIndex的值>=0 for (int i = editingTPlan.Count - 1; i >= 0; i--) { //删除超过时段的计划 if (!IsTimeRight(cboPeriod.SelectedIndex, editingTPlan[i].PushTime)) { editingTPlan.RemoveAt(i); } else { break; } } txtInsertRoom.Text = GetNextRoomNum(room).ToString("000"); txtInsertPushTime.Text = time.AddMinutes(BreakTime).ToString("t"); dgEdit.ItemsSource = null; dgEdit.ItemsSource = editingTPlan; }
private void TxtDisplayFstPlan(TPushPlan plan) { txtRoom.Text = plan.RoomNum.ToString("000"); //txtPushTime.Text = plan.TxtPushTime; //txtBurnTime.Text = plan.StrBurnTime; }