public List <CFinishHistory> GetOpFinishHistory(string orderuid) { SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "SELECT eventMessage,eventTime,finishedQty,failedQty,planQty,jobQty,mesOperator FROM wapMesEventRec WHERE OrderUID = '" + orderuid + "' ORDER BY EventTime"; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dthistory = new DataTable(); da.Fill(dthistory); da.Dispose(); cmd.Connection.Close(); List <CFinishHistory> cFinishHistories = new List <CFinishHistory>(); foreach (DataRow item in dthistory.Rows) { CFinishHistory cFinish = new CFinishHistory { EventMessage = item["eventMessage"].ToString(), EventTime = PublicFunc.ForMatDateTimeStr(Convert.ToDateTime(item["eventTime"]), 1), FinishedQty = Convert.ToDouble(item["finishedQty"]), FailedQty = Convert.ToDouble(item["failedQty"]), PlannedQty = Convert.ToDouble(item["planQty"]), JobQty = Convert.ToDouble(item["jobQty"]), MesOperator = item["mesOperator"].ToString() }; cFinishHistories.Add(cFinish); } return(cFinishHistories); }
public bool PauseOrder_Call(string jsonedata) { COrderList mesEvent = JsonConvert.DeserializeObject <COrderList>(jsonedata); //写队列 WriteMesEvent writeMes = new WriteMesEvent(); if (writeMes.WriteMesEvent_Call(mesEvent, 3)) { SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "UPDATE User_MesDailyData SET TaskFinishState = '3',MesResName = '" + mesEvent.MesResName + "', MesOpName = '" + mesEvent.MesOpName + "', bgPerson = '" + mesEvent.MesOperator + "', updateDateTime = '" + DateTime.Now + "' WHERE UID = '" + mesEvent.OrderUID + "'"; int result = cmd.ExecuteNonQuery(); cmd.Connection.Close(); if (result == 1) { return(true); } else { return(false); } } else { return(false); } }
public void SetResUnused(string resName, string useType) { SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "DELETE FROM wapResLockState WHERE ResName = '" + resName + "' and ResEventType = '" + useType + "'"; cmd.ExecuteNonQuery(); cmd.Connection.Close(); }
//查询是否有其他订单是否换班 private void EndOtherOrder(string resname) { MUnStartList unStartList = new MUnStartList(); List <COrderList> cOrders = unStartList.GetUnStartOrderList(resname); if (cOrders.Count > 0) { foreach (COrderList item in cOrders) { //查询下一个班次是哪天,第几个班次 SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "SELECT MAX(dayShift) FROM User_MesDailyData WHERE pmResName = '" + item.PmResName + "' and mesDailyDate ='" + PublicFunc.GetDailyDate(thisresname) + "'"; SqlDataReader rd = cmd.ExecuteReader(); rd.Read(); int maxdayshift = Convert.ToInt32(rd[0]); rd.Close(); cmd.Connection.Close(); int nextdayshift; DateTime nextdailydate; if (item.DayShift < maxdayshift) { nextdayshift = item.DayShift + 1; nextdailydate = PublicFunc.GetDailyDate(thisresname); } else { nextdayshift = 1; nextdailydate = PublicFunc.GetDailyDate(thisresname).AddDays(1); } //先查找这个设备上的下个班次是否有这个订单 cmd = PmConnections.SchCmd(); //SELECT COUNT(UID) FROM [sch_test].[dbo].[User_MesDailyData] where pmResName = '纽威立式车床17:2' and mesDailyDate = '2020-6-20' and workID = '0021905001' and dayShift = 1 and productID = '8311280776' and pmOpName = '精车一' cmd.CommandText = "SELECT COUNT(UID) FROM User_MesDailyData WHERE pmResName = '" + thisresname + "' and mesDailyDate = '" + nextdailydate + "' and dayshift = '" + nextdayshift + "' and workid = '" + item.WorkID + "' and productid = '" + item.ProductID + "' and pmOpName = '" + item.PmOpName + "'"; rd = cmd.ExecuteReader(); rd.Read(); int hasthisorder = Convert.ToInt32(rd[0]); rd.Close(); cmd.Connection.Close(); if (hasthisorder < 1) { cmd = PmConnections.SchCmd(); cmd.CommandText = "UPDATE User_MesDailyData SET mesDailyDate = '" + nextdailydate + "', dayshift = '" + nextdayshift + "' WHERE UID = '" + item.OrderUID + "'"; cmd.ExecuteNonQuery(); cmd.Connection.Close(); } else { cmd = PmConnections.SchCmd(); cmd.CommandText = "UPDATE User_MesDailyData SET TaskFinishState = '5' WHERE UID = '" + item.OrderUID + "'"; cmd.ExecuteNonQuery(); cmd.Connection.Close(); } } } }
public bool Report_Call(string jsonedata) { COrderList mesEvent = JsonConvert.DeserializeObject <COrderList>(jsonedata); WriteMesEvent writeMes = new WriteMesEvent(); if (writeMes.WriteMesEvent_Call(mesEvent, 2)) { //更新mesdailydata SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "SELECT finishedQty,AllfinishedQty,AllJobTaskQty FROM User_MesDailyData WHERE UID = '" + mesEvent.OrderUID + "'"; SqlDataReader rd = cmd.ExecuteReader(); rd.Read(); double serverallfinishedQty = Convert.ToDouble(rd[1]); double serverfinishedqty = Convert.ToDouble(rd[0]); double alljobtaskqty = Convert.ToDouble(rd[2]); rd.Close(); int taskfinishedstate; if ((serverallfinishedQty + mesEvent.FinishedQty + mesEvent.FailedQty) == alljobtaskqty) { taskfinishedstate = 4; } else { if ((serverfinishedqty + mesEvent.FinishedQty + mesEvent.FailedQty) >= mesEvent.Plannedqty) { taskfinishedstate = 4; } else { taskfinishedstate = 2; } } cmd.CommandText = "UPDATE User_MesDailyData SET mesResName = '" + mesEvent.MesResName + "', mesOpName = '" + mesEvent.MesOpName + "',finishedQty = finishedQty + '" + (mesEvent.FinishedQty + mesEvent.FailedQty) + "', failQty = failQty + '" + mesEvent.FailedQty + "', endDateTime = '" + mesEvent.ReportTime + "', updateDateTime = '" + DateTime.Now + "', bgPerson = '" + mesEvent.MesOperator + "',ScrappedQty = ScrappedQty + '" + mesEvent.ScrappedQty + "', TaskFinishState = '" + taskfinishedstate + "',UserComment = '" + mesEvent.UserComment + " ' WHERE UID = '" + mesEvent.OrderUID + "'"; cmd.ExecuteNonQuery(); cmd.CommandText = "UPDATE User_MesDailyData SET AllFinishedQty = AllFinishedQty + '" + (mesEvent.FinishedQty + mesEvent.FailedQty) + "', updateDateTime ='" + DateTime.Now + "' WHERE workID = '" + mesEvent.WorkID + "' and productID = '" + mesEvent.ProductID + "' and pmOpName = '" + mesEvent.PmOpName + "'"; int result = cmd.ExecuteNonQuery(); cmd.Connection.Close(); if (result > 0) { return(true); } else { return(false); } } else { return(false); } }
public void SetResUsed(string empid, string resName, string useType, string lockedStartTime, string lockedEndTime, string eventMessage) { int pmuid = PublicFunc.GetMaxUID("S", "wapResLockState", "PMUID"); string username = PublicFunc.GetEmpName(Convert.ToInt32(empid)); SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "INSERT INTO wapResLockState (PMUID,ResName,LockedStartTime,LockedEndTime,LockedPerson,ResEventType,ResEventComment) VALUES ('" + pmuid + "','" + resName + "','" + lockedStartTime + "','" + lockedEndTime + "','" + username + "','" + useType + "','" + eventMessage + "')"; cmd.ExecuteNonQuery(); cmd.Connection.Close(); }
public DataTable Operate(string empName) { DataTable table = new DataTable(); SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "select * from wapMesEventRec where MesOperator = '" + empName + "'"; SqlDataAdapter ad = new SqlDataAdapter(cmd); ad.Fill(table); ad.Dispose(); cmd.Connection.Close(); return(table); }
public bool BeginDown_Call(string orderuid, string resName, string dayshift) { SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "UPDATE User_MesDailyData SET pmresname = '" + resName + "', updateDatetime ='" + DateTime.Now + "', bgPerson = '" + PmUser.UserName + "',dayShift = '" + dayshift + "',mesdailydate = '" + DateTime.Now.Date + "' WHERE UID = '" + orderuid + "'"; int result = cmd.ExecuteNonQuery(); cmd.Connection.Close(); if (result == 1) { return(true); } else { return(false); } }
public bool OrderAjustmest_Call(string jsonEdata) { COrderList mesEvent = JsonConvert.DeserializeObject <COrderList>(jsonEdata); SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "UPDATE User_MesDailyData SET adjustment = '1' WHERE UID = '" + mesEvent.OrderUID + "'"; int result = cmd.ExecuteNonQuery(); cmd.Connection.Close(); if (result == 1) { return(true); } else { return(false); } }
public bool Resume_Call(string jsonedata) { COrderList mesEvent = JsonConvert.DeserializeObject<COrderList>(jsonedata); WriteMesEvent writeMes = new WriteMesEvent(); if(writeMes.WriteMesEvent_Call(mesEvent,4)) { SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "UPDATE User_MesDailyData SET TaskFinishState = '0' WHERE UID = '" + mesEvent.OrderUID + "'"; int result = cmd.ExecuteNonQuery(); cmd.Connection.Close(); if (result == 1) { return true; } else { return false; } } else { return false; } }
public bool ChangeResource_Call(string jsonedata) { COrderList mesEvent = JsonConvert.DeserializeObject <COrderList>(jsonedata); WriteMesEvent writeMes = new WriteMesEvent(); if (writeMes.WriteMesEvent_Call(mesEvent, 5)) { SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "UPDATE User_MesDailyData SET pmResName = '" + mesEvent.ChangeResName + "' WHERE UID = '" + mesEvent.OrderUID + "'"; int result = cmd.ExecuteNonQuery(); if (result == 1) { return(true); } else { return(false); } } else { return(false); } }
public List <COrderList> CanDownThisRes_Call(string resname, int dayshift) { SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "SELECT * FROM User_MesDailyData WHERE resCanUsed like '%" + resname.Split(':')[0] + "%' and datatype = 'P' and dailyDate >='" + DateTime.Now + "' and TaskFinishState < '4' ORDER BY workid,productid,pmresname,pmopname,PlanStartTime Desc"; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable data = new DataTable(); da.Fill(data); da.Dispose(); cmd.Connection.Close(); //获取现有设备上的工单数据 cmd.CommandText = "SELECT pmresname,pmopname,workid FROM User_MesDailyData WHERE pmresname = '" + resname + "' and datatype ='P' and taskfinishstate < 4 and dailydate = '" + DateTime.Now.Date + "' and dayshift = '" + dayshift + "'"; da = new SqlDataAdapter(cmd); DataTable dtthisrestasks = new DataTable(); da.Fill(dtthisrestasks); da.Dispose(); cmd.Connection.Close(); //对拉取过来的数据去重 DataTable newdata = data.Clone(); string thisworkid, preworkid = string.Empty; string thisproduct, preproduct = string.Empty; string thisresname, preresname = string.Empty; string thisopname, preopname = string.Empty; for (int i = 0; i < data.Rows.Count; i++) { if (i == 0) { preworkid = data.Rows[i]["workid"].ToString(); preproduct = data.Rows[i]["productid"].ToString(); preresname = data.Rows[i]["pmresname"].ToString(); preopname = data.Rows[i]["pmopname"].ToString(); continue; } else { thisworkid = data.Rows[i]["workid"].ToString(); thisproduct = data.Rows[i]["productid"].ToString(); thisresname = data.Rows[i]["pmresname"].ToString(); thisopname = data.Rows[i]["pmopname"].ToString(); DataRow[] finddr = dtthisrestasks.Select("pmresname = '" + data.Rows[i]["pmresname"].ToString() + "' and pmopname = '" + data.Rows[i]["pmopname"].ToString() + "' and workid = '" + data.Rows[i]["workid"].ToString() + "'"); if (finddr.Count() > 0) { continue; } if (thisworkid == preworkid) { //工单一样,比较产品是否一样 if (thisproduct == preproduct) { //产品一样 比较设备是否一样 if (thisresname == preresname) { //如果设备一样,比较工序是否一样 if (thisopname == preopname) { continue; } else { DataRow dr = newdata.NewRow(); dr.ItemArray = data.Rows[i].ItemArray; newdata.Rows.Add(dr); } } else { //设备不一样 添加 DataRow dr = newdata.NewRow(); dr.ItemArray = data.Rows[i].ItemArray; newdata.Rows.Add(dr); } } else { //如果产品不一样,添加 DataRow dr = newdata.NewRow(); dr.ItemArray = data.Rows[i].ItemArray; newdata.Rows.Add(dr); } } else { //工单不一样,直接添加 DataRow dr = newdata.NewRow(); dr.ItemArray = data.Rows[i].ItemArray; newdata.Rows.Add(dr); } preworkid = thisworkid; preproduct = thisproduct; preresname = thisresname; preopname = thisopname; } } DataView dv = newdata.DefaultView; dv.Sort = "PlanStartTime ASC"; newdata = dv.ToTable(); List <COrderList> orderlist = new List <COrderList>(); if (newdata.Rows.Count > 0) { foreach (DataRow item in newdata.Rows) { DataRow checkeddata = PublicFunc.CheckEmptyVal(data, item); COrderList cOrder = new COrderList() { MesResName = checkeddata["MesResName"].ToString(), MesOpName = checkeddata["MesOpName"].ToString(), MesOperator = checkeddata["bgPerson"].ToString(), WorkID = checkeddata["WorkID"].ToString(), PlanStartTime = PublicFunc.ForMatDateTimeStr(Convert.ToDateTime(checkeddata["PlanStartTime"]), 1), Planendtime = PublicFunc.ForMatDateTimeStr(Convert.ToDateTime(checkeddata["Planendtime"]), 1), PmResName = checkeddata["PmResName"].ToString(), PmOpName = checkeddata["PmOpName"].ToString(), ProductID = checkeddata["ProductID"].ToString(), TaskFinishState = Convert.ToInt32(checkeddata["TaskFinishState"]), FinishedQty = Convert.ToDouble(checkeddata["FinishedQty"]), Plannedqty = Convert.ToDouble(checkeddata["Plannedqty"]), FailedQty = Convert.ToDouble(checkeddata["FailQty"]), AllFinishedQty = Convert.ToDouble(checkeddata["AllFinishedQty"]), JobQty = Convert.ToDouble(checkeddata["JobQty"]), ItemAttr1 = checkeddata["ItemAttr1"].ToString(), ItemAttr2 = checkeddata["ItemAttr2"].ToString(), ItemAttr3 = checkeddata["ItemAttr3"].ToString(), ItemAttr4 = checkeddata["ItemAttr4"].ToString(), DayShift = Convert.ToInt32(checkeddata["DayShift"]), ItemDesp = checkeddata["itemDesp"].ToString(), WorkHours = Convert.ToDouble(checkeddata["workHour"]), SetupTime = Convert.ToDouble(checkeddata["setupTime"]), OrderUID = Convert.ToInt32(checkeddata["UID"]), BomComused = Convert.ToDouble(checkeddata["AllJobTaskqty"]) / Convert.ToDouble(checkeddata["JobQty"]), CanReport = true, CanReportQty = Convert.ToDouble(checkeddata["AllJobTaskqty"]) - Convert.ToDouble(checkeddata["AllFinishedQty"]), ChangeResName = string.Empty }; orderlist.Add(cOrder); } bool hasoutput = false; foreach (COrderList c in orderlist) { if (c.TaskFinishState != 0 && c.TaskFinishState != 3) { hasoutput = true; } else { continue; } } if (hasoutput == true) { foreach (COrderList c in orderlist) { if (c.TaskFinishState != 0) { c.CanReport = true; } else { c.CanReport = false; } } } } //处理重复的数据 return(orderlist); }
/// <summary> /// 执行写入mes事件队列的方法 /// </summary> /// <param name="edata">api接收到的数据</param> /// <param name="writetype">0:开始切换;1:结束切换;2:报工;3:暂停;4:恢复生产;5:切换设备;6:换班</param> /// <returns>SQL执行结果bool值</returns> public bool WriteMesEvent_Call(COrderList edata, int writetype) { SqlCommand cmd = PmConnections.SchCmd(); int maxUID = PublicFunc.GetMaxUID("S", "wapMesEventRec", "PMUID"); if (writetype == 0) { cmd.CommandText = @"INSERT INTO wapMesEventRec (PMUID,EventType,EventName,EventMessage,EventTime,ResName,WorkID,OpName,ProductID,Description,JobQty,FinishedQty,MesDate,MesOperator,FailedQty,ScrappedQty,DayShift,PlanQty,OrderUID) VALUES ('" + maxUID + "','S','StartChange','开始切换','" + DateTime.Now + "','" + edata.MesResName + "','" + edata.WorkID + "','" + edata.MesOpName + "','" + edata.ProductID + "','" + edata.ItemDesp + "','" + edata.JobQty + "','" + edata.FinishedQty + "','" + DateTime.Now.Date + "','" + edata.MesOperator + "','" + edata.FailedQty + "','" + edata.ScrappedQty + "','" + edata.DayShift + "','" + edata.Plannedqty + "','" + edata.OrderUID + "')"; } else if (writetype == 1) { cmd.CommandText = @"INSERT INTO wapMesEventRec (PMUID,EventType,EventName,EventMessage,EventTime,ResName,WorkID,OpName,ProductID,Description,JobQty,FinishedQty,MesDate,MesOperator,FailedQty,ScrappedQty,DayShift,PlanQty,OrderUID) VALUES ('" + maxUID + "','E','EndChange','结束切换','" + DateTime.Now + "','" + edata.MesResName + "','" + edata.WorkID + "','" + edata.MesOpName + "','" + edata.ProductID + "','" + edata.ItemDesp + "','" + edata.JobQty + "','" + edata.FinishedQty + "','" + DateTime.Now.Date + "','" + edata.MesOperator + "','" + edata.FailedQty + "','" + edata.ScrappedQty + "','" + edata.DayShift + "','" + edata.Plannedqty + "','" + edata.OrderUID + "')"; } else if (writetype == 2) { cmd.CommandText = @"INSERT INTO wapMesEventRec (PMUID,EventType,EventName,EventMessage,EventTime,ResName,WorkID,OpName,ProductID,Description,JobQty,FinishedQty,MesDate,MesOperator,FailedQty,ScrappedQty,DayShift,PlanQty,OrderUID,MesAttr1) VALUES ('" + maxUID + "','R','Report','报工','" + DateTime.Now + "','" + edata.MesResName + "','" + edata.WorkID + "','" + edata.MesOpName + "','" + edata.ProductID + "','" + edata.ItemDesp + "','" + edata.JobQty + "','" + edata.FinishedQty + "','" + DateTime.Now.Date + "','" + edata.MesOperator + "','" + edata.FailedQty + "','" + edata.ScrappedQty + "','" + edata.DayShift + "','" + edata.Plannedqty + "','" + edata.OrderUID + "','" + edata.UserComment + "')"; } else if (writetype == 3) { cmd.CommandText = @"INSERT INTO wapMesEventRec (PMUID,EventType,EventName,EventMessage,EventTime,ResName,WorkID,OpName,ProductID,Description,JobQty,FinishedQty,MesDate,MesOperator,FailedQty,ScrappedQty,DayShift,PlanQty,OrderUID) VALUES ('" + maxUID + "','P','Pause','暂停生产','" + DateTime.Now + "','" + edata.MesResName + "','" + edata.WorkID + "','" + edata.MesOpName + "','" + edata.ProductID + "','" + edata.ItemDesp + "','" + edata.JobQty + "','" + edata.FinishedQty + "','" + DateTime.Now.Date + "','" + edata.MesOperator + "','" + edata.FailedQty + "','" + edata.ScrappedQty + "','" + edata.DayShift + "','" + edata.Plannedqty + "','" + edata.OrderUID + "')"; } else if (writetype == 4) { cmd.CommandText = @"INSERT INTO wapMesEventRec (PMUID,EventType,EventName,EventMessage,EventTime,ResName,WorkID,OpName,ProductID,Description,JobQty,FinishedQty,MesDate,MesOperator,FailedQty,ScrappedQty,DayShift,PlanQty,OrderUID) VALUES ('" + maxUID + "','U','Resume','恢复生产','" + DateTime.Now + "','" + edata.MesResName + "','" + edata.WorkID + "','" + edata.MesOpName + "','" + edata.ProductID + "','" + edata.ItemDesp + "','" + edata.JobQty + "','" + edata.FinishedQty + "','" + DateTime.Now.Date + "','" + edata.MesOperator + "','" + edata.FailedQty + "','" + edata.ScrappedQty + "','" + edata.DayShift + "','" + edata.Plannedqty + "','" + edata.OrderUID + "')"; } else if (writetype == 5) { cmd.CommandText = @"INSERT INTO wapMesEventRec (PMUID,EventType,EventName,EventMessage,EventTime,ResName,WorkID,OpName,ProductID,Description,JobQty,FinishedQty,MesDate,MesOperator,FailedQty,ScrappedQty,DayShift,PlanQty,OrderUID) VALUES ('" + maxUID + "','C','ChangeRes','推送订单到=>" + edata.ChangeResName + "','" + DateTime.Now + "','" + edata.MesResName + "','" + edata.WorkID + "','" + edata.MesOpName + "','" + edata.ProductID + "','" + edata.ItemDesp + "','" + edata.JobQty + "','" + edata.FinishedQty + "','" + DateTime.Now.Date + "','" + edata.MesOperator + "','" + edata.FailedQty + "','" + edata.ScrappedQty + "','" + edata.DayShift + "','" + edata.Plannedqty + "','" + edata.OrderUID + "')"; } else if (writetype == 6) { cmd.CommandText = @"INSERT INTO wapMesEventRec (PMUID,EventType,EventName,EventMessage,EventTime,ResName,WorkID,OpName,ProductID,Description,JobQty,FinishedQty,MesDate,MesOperator,FailedQty,ScrappedQty,DayShift,PlanQty,OrderUID) VALUES ('" + maxUID + "','EW','EndWorking','换班','" + DateTime.Now + "','" + edata.MesResName + "','" + edata.WorkID + "','" + edata.MesOpName + "','" + edata.ProductID + "','" + edata.ItemDesp + "','" + edata.JobQty + "','" + edata.FinishedQty + "','" + DateTime.Now.Date + "','" + edata.MesOperator + "','" + edata.FailedQty + "','" + edata.ScrappedQty + "','" + edata.DayShift + "','" + edata.Plannedqty + "','" + edata.OrderUID + "')"; } int result = cmd.ExecuteNonQuery(); cmd.Connection.Close(); if (result == 1) { return(true); } else { return(false); } }
public COpFinish GetOpFinishedData(string jsonedata) { COrderList order = JsonConvert.DeserializeObject <COrderList>(jsonedata); SqlCommand cmd = PmConnections.SchCmd(); //获取计划数据 cmd.CommandText = "SELECT * FROM User_MesDailyData WHERE UID = '" + order.OrderUID + "'"; SqlDataReader rd = cmd.ExecuteReader(); rd.Read(); DateTime planstarttime = Convert.ToDateTime(rd["planStartTime"]); DateTime planendtime = Convert.ToDateTime(rd["planEndTime"]); double plannedsetuphours = Convert.ToDouble(rd["setupTime"]); int setuptime = Convert.ToInt32(plannedsetuphours * 60); double plannedqty = Convert.ToDouble(rd["plannedQty"]); double plannedhours = Convert.ToDouble(rd["workHour"]); double failedqty = Convert.ToDouble(rd["failQty"]); double finishedqty = Convert.ToDouble(rd["finishedqty"]); rd.Close(); DateTime plansetupstarttime = planstarttime.AddMinutes(-setuptime); DateTime plansetupendtime = planstarttime; //获取实际数据 cmd.CommandText = "SELECT * FROM wapMesEventRec WHERE OrderUID = '" + order.OrderUID + "' order by EventTime"; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dtmesdata = new DataTable(); da.Fill(dtmesdata); da.Dispose(); cmd.Connection.Close(); //计算数据 COpFinish returndata = new COpFinish { PlanStartTime = PublicFunc.ForMatDateTimeStr(planstarttime, 1), PlanEndTime = PublicFunc.ForMatDateTimeStr(planendtime, 1), PlannedHours = plannedhours * 3600, PlannedQty = plannedqty, PlanSetupStartTime = PublicFunc.ForMatDateTimeStr(plansetupstarttime, 1), PlanSetupEndTime = PublicFunc.ForMatDateTimeStr(plansetupendtime, 1), PlannedSetupHours = plannedsetuphours * 3600, FinishedQty = finishedqty, FailedQty = failedqty }; //开始计算mes数据 //获取mes切换开始时间 double messetuphours = 0; double meshours = 0; for (int i = 0; i < dtmesdata.Rows.Count; i++) { if (dtmesdata.Rows[i]["EventType"].ToString().Equals("S")) { messetuphours += (Convert.ToDateTime(dtmesdata.Rows[i + 1]["EventTime"]) - Convert.ToDateTime(dtmesdata.Rows[i]["EventTime"])).TotalSeconds; if (dtmesdata.Rows[i + 1]["EventType"].ToString().Equals("E")) { returndata.MesSetupStartTime = PublicFunc.ForMatDateTimeStr(Convert.ToDateTime(dtmesdata.Rows[i]["EventTime"]), 1); returndata.MesSetupEndTime = PublicFunc.ForMatDateTimeStr(Convert.ToDateTime(dtmesdata.Rows[i + 1]["EventTime"]), 1); } } if (dtmesdata.Rows[i]["EventType"].ToString().Equals("E")) { if (dtmesdata.Rows[i + 1]["EventType"].ToString().Equals("R")) { meshours += (Convert.ToDateTime(dtmesdata.Rows[i + 1]["EventTime"]) - Convert.ToDateTime(dtmesdata.Rows[i]["EventTime"])).TotalSeconds; returndata.MesStartTime = PublicFunc.ForMatDateTimeStr(Convert.ToDateTime(dtmesdata.Rows[i]["EventTime"]), 1); returndata.MesEndTime = PublicFunc.ForMatDateTimeStr(Convert.ToDateTime(dtmesdata.Rows[i + 1]["EventTime"]), 1); } } } returndata.MesSetupHours = Convert.ToDouble(messetuphours.ToString("0.00")); returndata.MesHours = Convert.ToDouble(meshours.ToString("0.00")); return(returndata); }
public List <COrderList> GetUnStartOrderList(string resName) { int dayshift = PublicFunc.GetDayShift(resName); DateTime mesdailydate = PublicFunc.GetDailyDate(resName); SqlCommand cmd = PmConnections.SchCmd(); cmd.CommandText = "SELECT * FROM User_MesDailyData WHERE pmResName = '" + resName + "' and datatype = 'P' and mesdailyDate ='" + mesdailydate.Date + "' and TaskFinishState < '4' and dayShift = '" + dayshift + "' ORDER BY mesdailyDate,planStartTime"; //cmd.CommandText = "SELECT * FROM User_MesDailyData WHERE pmResName = '" + resName + "' and datatype = 'P'and TaskFinishState < '4' and dayShift = '" + shift + "'ORDER BY dailyDate,planStartTime"; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable returndata = new DataTable(); da.Fill(returndata); da.Dispose(); cmd.Connection.Close(); if (returndata.Rows.Count < 1) { return(null); } else { List <COrderList> LiReturnData = new List <COrderList>(); foreach (DataRow item in returndata.Rows) { DataRow checkeddata = PublicFunc.CheckEmptyVal(returndata, item); COrderList li = new COrderList { MesResName = checkeddata["MesResName"].ToString(), MesOpName = checkeddata["MesOpName"].ToString(), MesOperator = checkeddata["bgPerson"].ToString(), WorkID = checkeddata["WorkID"].ToString(), PlanStartTime = PublicFunc.ForMatDateTimeStr(Convert.ToDateTime(checkeddata["PlanStartTime"]), 1), Planendtime = PublicFunc.ForMatDateTimeStr(Convert.ToDateTime(checkeddata["Planendtime"]), 1), PmResName = checkeddata["PmResName"].ToString(), PmOpName = checkeddata["PmOpName"].ToString(), ProductID = checkeddata["ProductID"].ToString(), TaskFinishState = Convert.ToInt32(checkeddata["TaskFinishState"]), FinishedQty = Convert.ToDouble(checkeddata["FinishedQty"]), Plannedqty = Convert.ToDouble(checkeddata["Plannedqty"]), FailedQty = Convert.ToDouble(checkeddata["FailQty"]), AllFinishedQty = Convert.ToDouble(checkeddata["AllFinishedQty"]), JobQty = Convert.ToDouble(checkeddata["JobQty"]), ItemAttr1 = checkeddata["ItemAttr1"].ToString(), ItemAttr2 = checkeddata["ItemAttr2"].ToString(), ItemAttr3 = checkeddata["ItemAttr3"].ToString(), ItemAttr4 = checkeddata["ItemAttr4"].ToString(), DayShift = Convert.ToInt32(checkeddata["DayShift"]), ItemDesp = checkeddata["itemDesp"].ToString(), WorkHours = Convert.ToDouble(checkeddata["workHour"]), SetupTime = Convert.ToDouble(checkeddata["setupTime"]), OrderUID = Convert.ToInt32(checkeddata["UID"]), BomComused = Convert.ToDouble(checkeddata["AllJobTaskqty"]) / Convert.ToDouble(checkeddata["JobQty"]), CanReport = true, CanReportQty = Convert.ToDouble(checkeddata["AllJobTaskqty"]) - Convert.ToDouble(checkeddata["AllFinishedQty"]) - Convert.ToDouble(checkeddata["FailQty"]), ChangeResName = string.Empty, ReportTime = Convert.ToDateTime(checkeddata["updateDatetime"]), JobDemandDay = Convert.ToDateTime(checkeddata["jobDemandDay"]), ScrappedQty = Convert.ToDouble(checkeddata["ScrappedQty"]), Ajustment = Convert.ToBoolean(checkeddata["adjustment"]), UnitPrice = Convert.ToDouble(checkeddata["unitPrice"]), MesSetupStartTime = Convert.ToDateTime(checkeddata["setupStartTime"]), MesSetupEndTime = Convert.ToDateTime(checkeddata["setupEndTime"]), MesStartTime = Convert.ToDateTime(checkeddata["startDateTime"]), MesEndTime = Convert.ToDateTime(checkeddata["endDateTime"]), UserComment = checkeddata["userComment"].ToString() }; LiReturnData.Add(li); } //public DateTime MesStartTime { get; set; } //public DateTime MesEndTime { get; set; } //public DateTime MesSetupStartTime { get; set; } //public DateTime MesSetupEndtime { get; set; } bool hasoutput = false; foreach (COrderList c in LiReturnData) { if (c.TaskFinishState != 0 && c.TaskFinishState != 3) { hasoutput = true; } else { continue; } } if (hasoutput == true) { foreach (COrderList c in LiReturnData) { if (c.TaskFinishState != 0) { c.CanReport = true; } else { c.CanReport = false; } } } return(LiReturnData); } }
public bool EndWork(string jsonedata) { COrderList mesEvent = JsonConvert.DeserializeObject <COrderList>(jsonedata); WriteMesEvent writeMes = new WriteMesEvent(); if (writeMes.WriteMesEvent_Call(mesEvent, 6)) { thisresname = mesEvent.MesResName; SqlDataReader rd; SqlCommand cmd; int taskfinishedstate = -1; if (mesEvent.TaskFinishState == 2) { //更新mesdailydata cmd = PmConnections.SchCmd(); cmd.CommandText = "SELECT finishedQty,AllfinishedQty,AllJobTaskQty FROM User_MesDailyData WHERE UID = '" + mesEvent.OrderUID + "'"; rd = cmd.ExecuteReader(); rd.Read(); double serverallfinishedQty = Convert.ToDouble(rd[1]); double serverfinishedqty = Convert.ToDouble(rd[0]); double alljobtaskqty = Convert.ToDouble(rd[2]); rd.Close(); if ((serverallfinishedQty + mesEvent.FinishedQty + mesEvent.FailedQty) == alljobtaskqty) { taskfinishedstate = 4; } else { if ((serverfinishedqty + mesEvent.FinishedQty + mesEvent.FailedQty) >= mesEvent.Plannedqty) { taskfinishedstate = 4; } else { taskfinishedstate = 2; } } cmd.CommandText = "UPDATE User_MesDailyData SET mesResName = '" + mesEvent.MesResName + "', mesOpName = '" + mesEvent.MesOpName + "',finishedQty = finishedQty + '" + (mesEvent.FinishedQty + mesEvent.FailedQty) + "', failQty = failQty + '" + mesEvent.FailedQty + "', endDateTime = '" + mesEvent.ReportTime + "', updateDateTime = '" + DateTime.Now + "', bgPerson = '" + mesEvent.MesOperator + "',ScrappedQty = ScrappedQty + '" + mesEvent.ScrappedQty + "', TaskFinishState = '" + taskfinishedstate + "' WHERE UID = '" + mesEvent.OrderUID + "'"; cmd.ExecuteNonQuery(); cmd.CommandText = "UPDATE User_MesDailyData SET AllFinishedQty = AllFinishedQty + '" + (mesEvent.FinishedQty + mesEvent.FailedQty) + "', updateDateTime ='" + DateTime.Now + "' WHERE workID = '" + mesEvent.WorkID + "' and productID = '" + mesEvent.ProductID + "' and pmOpName = '" + mesEvent.PmOpName + "'"; cmd.ExecuteNonQuery(); cmd.Connection.Close(); } //查询下一个班次是哪天,第几个班次 cmd = PmConnections.SchCmd(); cmd.CommandText = "SELECT MAX(dayShift) FROM User_MesDailyData WHERE pmResName = '" + mesEvent.PmResName + "' and mesDailyDate ='" + PublicFunc.GetDailyDate(thisresname) + "'"; rd = cmd.ExecuteReader(); rd.Read(); int maxdayshift = Convert.ToInt32(rd[0]); rd.Close(); cmd.Connection.Close(); int nextdayshift; DateTime nextdailydate; if (mesEvent.DayShift < maxdayshift) { nextdayshift = mesEvent.DayShift + 1; nextdailydate = PublicFunc.GetDailyDate(thisresname); } else { nextdayshift = 1; nextdailydate = PublicFunc.GetDailyDate(thisresname).AddDays(1); } //先查找这个设备上的下个班次是否有这个订单 cmd = PmConnections.SchCmd(); //SELECT COUNT(UID) FROM [sch_test].[dbo].[User_MesDailyData] where pmResName = '纽威立式车床17:2' and mesDailyDate = '2020-6-20' and workID = '0021905001' and dayShift = 1 and productID = '8311280776' and pmOpName = '精车一' cmd.CommandText = "SELECT COUNT(UID) FROM User_MesDailyData WHERE pmResName = '" + thisresname + "' and mesDailyDate = '" + nextdailydate + "' and dayshift = '" + nextdayshift + "' and workid = '" + mesEvent.WorkID + "' and productid = '" + mesEvent.ProductID + "' and pmOpName = '" + mesEvent.PmOpName + "'"; rd = cmd.ExecuteReader(); rd.Read(); int hasthisorder = Convert.ToInt32(rd[0]); rd.Close(); cmd.Connection.Close(); if (taskfinishedstate == 4) { EndOtherOrder(thisresname); return(true); } else { if (hasthisorder < 1) { cmd = PmConnections.SchCmd(); cmd.CommandText = "UPDATE User_MesDailyData SET mesDailyDate = '" + nextdailydate + "', dayshift = '" + nextdayshift + "' WHERE UID = '" + mesEvent.OrderUID + "'"; int result = cmd.ExecuteNonQuery(); cmd.Connection.Close(); if (result > 0) { EndOtherOrder(thisresname); return(true); } else { return(false); } } else { cmd = PmConnections.SchCmd(); cmd.CommandText = "UPDATE User_MesDailyData SET TaskFinishState = '5' WHERE UID = '" + mesEvent.OrderUID + "'"; cmd.ExecuteNonQuery(); cmd.Connection.Close(); EndOtherOrder(thisresname); return(true); } } } else { return(false); } }