Esempio n. 1
0
        //查询是否有其他订单是否换班
        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();
                    }
                }
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
            }
        }