예제 #1
0
파일: CInTask.cs 프로젝트: wg3281/JZFJ
        private void SetInTaskStatus(int status)
        {
            string indexcolname = "";
            string custcolname  = "";

            foreach (DataGridViewColumn column in dataGridViewXs[superTabControl1.SelectedTab.Name].Columns)
            {
                if (column.DataPropertyName.ToUpper() == "INDEXNO")
                {
                    indexcolname = column.Name;
                }
            }


            foreach (DataGridViewRow selectedRow in dataGridViewXs[superTabControl1.SelectedTab.Name].SelectedRows)
            {
                //改变任务状态
                string indexcolvalue = selectedRow.Cells[indexcolname].Value.ToString();

                InTask inTask = InTask.GetInTaskByIndex(indexcolvalue);
                inTask.Status = status;
                inTask.SaveInTaskProcess(inTask.ID);
            }
        }
예제 #2
0
        protected override void DataPortal_Update()
        {
            //PLC写入下达任务

            //throw new Exception("写入下达任务");


            using (BypassPropertyChecks)
            {
                using (var cn = new MySqlConnection(AppUtility.AppUtil._LocalConnectionString))
                {
                    cn.Open();
                    using (var tran = cn.BeginTransaction())
                    {
                        try
                        {
                            using (var cm = cn.CreateCommand())
                            {
                                cm.Transaction = tran;
                                StringBuilder SQL = new StringBuilder();
                                SQL.Append("UPDATE T_InTaskIssued ");
                                SQL.Append("    SET ID = @ID,PLCFLAG = @PLCFLAG,PLCTASKNO = @PLCTASKNO,SLOCATION = @SLOCATION,CIGCODE = @CIGCODE,BARCODE = @BARCODE,INQTY = @INQTY ");
                                SQL.Append("  WHERE ID = @ID");
                                cm.CommandText = SQL.ToString();
                                cm.Parameters.AddWithValue("@ID", ID);
                                cm.Parameters.AddWithValue("@PLCFLAG", PLCFLAG);

                                cm.Parameters.AddWithValue("@PLCTASKNO", PLCTASKNO);
                                cm.Parameters.AddWithValue("@SLOCATION", SLOCATION);
                                cm.Parameters.AddWithValue("@CIGCODE", CIGCODE);
                                cm.Parameters.AddWithValue("@BARCODE", BARCODE);
                                cm.Parameters.AddWithValue("@INQTY", INQTY);
                                cm.ExecuteNonQuery();
                            }
                            tran.Commit();

                            if (PLCTASKNO != "0" && SLOCATION != "0" && INQTY != 0)
                            {
                                m_inTask = InTask.GetInTaskByIndex(PLCTASKNO);
                                if (m_inTask != null)
                                {
                                    m_inTask.Status = 2;
                                    m_inTask.SaveInTaskProcess(PLCTASKNO);
                                }
                                MonitorLog monitorLog = MonitorLog.NewMonitorLog();
                                monitorLog.LOGNAME  = "PLC任务下达";
                                monitorLog.LOGINFO  = "PLCTASKNO:" + PLCTASKNO.PadRight(10);
                                monitorLog.LOGINFO += CIGCODE + ":" +
                                                      BARCODE + ":" +
                                                      INQTY + "  ";
                                monitorLog.LOGLOCATION = "PLC";
                                monitorLog.LOGTYPE     = 0;
                                monitorLog.Save();
                            }
                            //else
                            //{
                            //    m_sortingLineTask = SortingLineTask.GetSortingLineByIndex(PLCTASKNO);
                            //    if (m_sortingLineTask != null)
                            //    {
                            //        m_sortingLineTask.Status = 2;
                            //        m_sortingLineTask.SaveSortingTaskProcess(PLCTASKNO);
                            //    }
                            //}
                        }
                        catch (Exception)
                        {
                            tran.Rollback();
                            throw;
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 补货任务下达方法
        /// </summary>
        /// <param name="task">未下达且序号最小的任务一条</param>
        /// <returns></returns>
        public PlCResult ReplenishmentTask(InTask task)
        {
            bool      isRun = false;
            PlcValue  writeValue;
            PlCResult plCResult = new PlCResult();

            try
            {
                PlcValue readValue = plc.GetPlcValue(ItemListEnum.db51Int0);
                if (Convert.ToInt32(readValue.Value) == 0)
                {
                    IntaskModel mdl = IntaskList.dic.FirstOrDefault(o => o.Key == Convert.ToInt32(task.PLCADDRESS)).Value;

                    int value = Convert.ToInt32(plc.GetPlcValue(mdl.TaskNoAddr).Value);

                    if (task.INDEXNO <= value)
                    {
                        task.Status = 1;
                        task.SaveInTaskProcess(task.ID);
                        plCResult.Succeed   = false;
                        plCResult.Exception = task.INDEXNO + "已经下达过!";
                        return(plCResult);
                    }
                    else
                    {
                        writeValue       = new PlcValue();
                        writeValue.Value = task.INDEXNO;
                        isRun            = plc.SetPlcValue(ItemListEnum.db51Int2, writeValue);

                        if (isRun)
                        {
                            writeValue       = new PlcValue();
                            writeValue.Value = task.ADDRESSCODE;
                            isRun            = plc.SetPlcValue(ItemListEnum.db51Int4, writeValue);
                        }

                        if (isRun)
                        {
                            writeValue       = new PlcValue();
                            writeValue.Value = task.BARCODE.Replace("6901028", "");
                            isRun            = plc.SetPlcValue(ItemListEnum.db51DInt6, writeValue);
                        }


                        if (isRun)
                        {
                            writeValue = new PlcValue();

                            if (task.INPORTCODE == "1")
                            {
                                writeValue.Value = 1;
                                isRun            = plc.SetPlcValue(ItemListEnum.db51Int10, writeValue);
                            }
                            else if (task.INPORTCODE == "2")
                            {
                                writeValue.Value = 2;
                                isRun            = plc.SetPlcValue(ItemListEnum.db51Int10, writeValue);
                            }
                        }


                        if (isRun)
                        {
                            writeValue       = new PlcValue();
                            writeValue.Value = 1;
                            isRun            = plc.SetPlcValue(ItemListEnum.db51Int0, writeValue);
                        }

                        if (isRun)
                        {
                            task.Status = 1;
                            task.SaveInTaskProcess(task.ID);
                            plCResult.Succeed = true;
                        }
                        else
                        {
                            plCResult.Succeed   = false;
                            plCResult.Exception = "任务号" + task.INDEXNO + "PLC补货任务写入异常";
                        }
                    }
                }
                else
                {
                    //如果下达区的标志为1不能下达时
                    //判断需要下达的任务号小于下达区的任务号直接改变任务状态
                    readValue = plc.GetPlcValue(ItemListEnum.db51Int2);
                    if (task.INDEXNO <= Convert.ToInt32(readValue.Value))
                    {
                        task.Status = 1;
                        task.SaveInTaskProcess(task.ID);
                        plCResult.Succeed   = false;
                        plCResult.Exception = task.INDEXNO + "已经下达过!";
                        return(plCResult);
                    }
                }
            }
            catch (Exception ex)
            {
                plCResult.Succeed   = false;
                plCResult.Exception = ex.Message;

                return(plCResult);
            }
            return(plCResult);
        }