Exemple #1
0
        /// <summary>出料邏輯</summary>
        private static PostResult POST_OUT(string DockDoorID, string ContainerID, string ContainerStatus, PostModel m)
        {
            PostResult r = new Models.ApiModel.PostResult();

            using (var db = new DataBase.OracleDataBase(Definition.WMSConn))
            {
                //判斷前次與此次上報時間,大於3秒則清空貨櫃清單,重新計算

                /*
                 * if (((DateTime.Now.Ticks - Definition.LastPostTime.Ticks) / 10000000) > 3) Definition.CONTAINERS.Clear();
                 * Definition.CONTAINERS.Add(ContainerID);
                 * Definition.LastPostTime = DateTime.Now;
                 *
                 * Thread.Sleep(3500); //等待時間內是否還有資料繼續上報
                 */

                //讀取指定棧板號碼的資料
                string strRFIDList = string.Join(",", m.pallets.Select(x => "'" + x.pallet + "'"));
                db.StrSQL = "SELECT * FROM " + DB_Prestr + "WMS_RFID_CHECK_LIST_VIEW WHERE (DOCK_DOOR_NO = '" + DockDoorID + "') AND (RFID IN (" + strRFIDList + "))";
                DataTable dtCheckList = db.ExecuteDataTable();

                #region 檢查RFID資訊是否異常
                foreach (PalletItem item in m.pallets)
                {
                    DataRow[] rows = dtCheckList.Select("RFID = '" + item.pallet + "'");
                    if (rows.Length == 1)
                    {
                        string strStatus = rows[0]["STATUS"].ToString();
                        if (strStatus != "0")
                        {
                            throw new Exception(item.pallet + "異常資訊");
                        }
                    }
                    else
                    {
                        throw new Exception(item.pallet + "異常資訊");
                    }
                }
                #endregion

                //判斷是否裝錯櫃
                //string strContainers = string.Join(",", Definition.CONTAINERS.Select(x => "'" + x + "'"));
                db.StrSQL = "SELECT CONTAINER_NO, PALLET_ID, RFID_OK_FLAG FROM " + DB_Prestr + "WMS_RFID_CONTAINER_CHECK_V WHERE (CONTAINER_NO = '" + ContainerID + "') AND (PALLET_ID IN (" + strRFIDList + "))";
                DataTable dtPallet        = db.ExecuteDataTable();
                var       listPallet      = dtPallet.AsEnumerable().Select(x => x.Field <string>("PALLET_ID"));
                var       listErrorPallet = m.pallets.FindAll(x => !listPallet.Contains(x.pallet)).Select(x => x.pallet);
                if (listErrorPallet.Count() > 0)
                {
                    throw new Exception(string.Join(",", listErrorPallet) + " 不屬於該貨櫃");
                }

                //過濾已用其他方式過帳的棧板資料
                listPallet = dtPallet.AsEnumerable().Where(x => x.Field <string>("RFID_OK_FLAG") == null && x.Field <string>("CONTAINER_NO") == ContainerID).Select(x => x.Field <string>("PALLET_ID"));
                var Rows = dtCheckList.AsEnumerable().Where(x => listPallet.Contains(x.Field <string>("RFID")));
                m.pallets = m.pallets.FindAll(x => listPallet.Contains(x.pallet));

                if (Rows.Count() > 0)
                {
                    //逐筆執行過帳
                    foreach (DataRow row in Rows)
                    {
                        //設定DB參數值
                        var param = new DataBase.SqlParams();
                        foreach (DataColumn col in dtCheckList.Columns)
                        {
                            param.Add(col.ColumnName, row[col.ColumnName].ToString());
                        }

                        db.SqlParams = param;
                        db.StrSQL    = "INSERT INTO " + DB_Prestr + "WMS_RFID_OK_LIST(PLANT, DOCK_DOOR_NO, ACTION, RFID, RESERVED_01, RESERVED_02, RESERVED_03, RESERVED_04, RESERVED_05, RESERVED_06, RESERVED_07, RESERVED_08, RESERVED_09, RESERVED_10, RESERVED_11, RESERVED_12, RESERVED_13, RESERVED_14, RESERVED_15, RESERVED_16, RESERVED_17, RESERVED_18, RESERVED_19, RESERVED_20) " +
                                       "VALUES(:PLANT, :DOCK_DOOR_NO, :ACTION, :RFID, :RESERVED_01, :RESERVED_02, '" + ContainerID + "', :RESERVED_04, :RESERVED_05, :RESERVED_06, :RESERVED_07, :RESERVED_08, :RESERVED_09, :RESERVED_10, :RESERVED_11, :RESERVED_12, :RESERVED_13, :RESERVED_14, :RESERVED_15, :RESERVED_16, :RESERVED_17, :RESERVED_18, :RESERVED_19, :RESERVED_20)";
                        db.ExecuteSQL();
                    }

                    //判斷裝載數量
                    string strNum, strTotal;
                    GetCountProcess(DockDoorID, ContainerID, ContainerStatus, out strNum, out strTotal);
                    if (strNum != strTotal)
                    {
                        r.result = "Y";
                        r.msg    = string.Format("櫃號:{0}({1}/{2})裝櫃中", ContainerID, strNum, strTotal);
                    }
                    else
                    {
                        r.result = "A";
                        r.msg    = string.Format("櫃號:{0}({1}/{2})裝櫃完成", ContainerID, strNum, strTotal);
                    }
                }
                else
                {
                    throw new Exception("無載貨資訊");
                }
            }

            return(r);
        }
Exemple #2
0
        /// <summary>收料邏輯</summary>
        private static PostResult POST_IN(string DockDoorID, string ContainerID, string ContainerStatus, PostModel m)
        {
            PostResult r = new Models.ApiModel.PostResult();

            using (var db = new DataBase.OracleDataBase(Definition.WMSConn))
            {
                //讀取指定棧板號碼的資料
                //20180214 增加 RESERVED_03 = ContainerID 條件 --> 要讓一單多車棧板資料可以上報(查詢出的資料只有一筆才合法)
                string strRFIDList = string.Join(",", m.pallets.Select(x => "'" + x.pallet + "'"));
                string strSQL      = "SELECT * FROM " + DB_Prestr + "WMS_RFID_CHECK_LIST_VIEW WHERE (RESERVED_03 = '" + ContainerID + "') AND (DOCK_DOOR_NO = '" + DockDoorID + "') AND (RFID IN (" + strRFIDList + "))";
                db.StrSQL = strSQL;
                DataTable dtCheckList = db.ExecuteDataTable();

                using (var dba = new DataBase.DataBase(Definition.Conn))
                {
                    //20180214 增加 --> 記錄 Select View SQL 語法
                    dba.StrSQL = "INSERT DebugSQL (sql,updatetime) VALUES ('" + strSQL.Replace("'", "") + "','" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "')";
                    dba.ExecuteSQL();
                }

                #region 檢查RFID資訊是否異常
                foreach (PalletItem item in m.pallets)
                {
                    DataRow[] rows = dtCheckList.Select("RFID = '" + item.pallet + "'");
                    if (rows.Length == 1)
                    {
                        string strStatus = rows[0]["STATUS"].ToString();
                        if (strStatus != "0")
                        {
                            throw new Exception(item.pallet + "異常資訊");
                        }
                    }
                    else
                    {
                        throw new Exception(item.pallet + "異常資訊");
                    }
                }
                #endregion

                //判斷卸櫃資料是否正確
                //20180226 增加 RESERVED_05 == Definition.AppPlant 條件 --> 確認屬於該廠的進貨
                var listPallet      = dtCheckList.AsEnumerable().Where(x => x.Field <string>("RESERVED_03") == ContainerID && x.Field <string>("RESERVED_05") == Definition.AppPlant).Select(x => x.Field <string>("RFID")).ToList();
                var listErrorPallet = m.pallets.FindAll(x => !listPallet.Contains(x.pallet)).Select(x => x.pallet);
                if (listErrorPallet.Count() > 0)
                {
                    throw new Exception(string.Join(",", listErrorPallet) + " 不屬於該廠區");
                }

                //逐筆執行過帳
                foreach (DataRow row in dtCheckList.Rows)
                {
                    //設定DB參數值
                    var param = new DataBase.SqlParams();
                    foreach (DataColumn col in dtCheckList.Columns)
                    {
                        param.Add(col.ColumnName, row[col.ColumnName].ToString());
                    }

                    db.SqlParams = param;
                    db.StrSQL    = "INSERT INTO " + DB_Prestr + "WMS_RFID_OK_LIST(PLANT, DOCK_DOOR_NO, ACTION, RFID, RESERVED_01, RESERVED_02, RESERVED_03, RESERVED_04, RESERVED_05, RESERVED_06, RESERVED_07, RESERVED_08, RESERVED_09, RESERVED_10, RESERVED_11, RESERVED_12, RESERVED_13, RESERVED_14, RESERVED_15, RESERVED_16, RESERVED_17, RESERVED_18, RESERVED_19, RESERVED_20) " +
                                   "VALUES(:PLANT, :DOCK_DOOR_NO, :ACTION, :RFID, :RESERVED_01, :RESERVED_02, :RESERVED_03, :RESERVED_04, :RESERVED_05, :RESERVED_06, :RESERVED_07, :RESERVED_08, :RESERVED_09, :RESERVED_10, :RESERVED_11, :RESERVED_12, :RESERVED_13, :RESERVED_14, :RESERVED_15, :RESERVED_16, :RESERVED_17, :RESERVED_18, :RESERVED_19, :RESERVED_20)";
                    db.ExecuteSQL();
                }

                //判斷卸載數量
                string strNum, strTotal;
                GetCountProcess(DockDoorID, ContainerID, ContainerStatus, out strNum, out strTotal);
                if (strNum != strTotal)
                {
                    r.result = "Y";
                    r.msg    = string.Format("櫃號:{0}({1}/{2})收料中", ContainerID, strNum, strTotal);
                }
                else
                {
                    r.result = "A";
                    r.msg    = string.Format("櫃號:{0}({1}/{2})收料完成", ContainerID, strNum, strTotal);
                }
            }

            return(r);
        }
Exemple #3
0
        /// <summary>上報至客戶端系統</summary>
        public static PostResult Post(PostModel m)
        {
            PostResult r           = new PostResult();
            string     strToDay    = DateTime.Now.ToString("yyyy/MM/dd");
            DataTable  dtCheckList = new DataTable();

            //取得此碼頭資料
            DataTable dtDockDoor         = DockDoorDataAccess.GetDockDoorList(null, m.ip, null, null, new Pages());
            DataRow   rowDoor            = dtDockDoor.Rows[0];
            string    strDockDoorID      = rowDoor["DockDoorID"].ToString();
            string    strContainerID     = rowDoor["ContainerID"].ToString();
            string    strContainerStatus = rowDoor["ContainerStatus"].ToString();
            string    strCaptionPanelIP  = rowDoor["CaptionPanelIP"].ToString();
            string    strFilterRules     = rowDoor["FilterRules"].ToString();
            int       iMask    = int.Parse(rowDoor["Mask"].ToString());
            int       iMaskOut = int.Parse(rowDoor["MaskOut"].ToString());

            //去除棧板的前後空白
            foreach (var item in m.pallets)
            {
                item.pallet = item.pallet.Trim();
            }

            //記錄原始上報資料
            string strData = JsonConvert.SerializeObject(m);

            //棧板白名單過濾機制
            if (strFilterRules.Trim() != "")
            {
                string[] rules = strFilterRules.Trim().Split(',');
                m.pallets.RemoveAll(x => !rules.Contains(x.pallet.Substring(0, 2)));
            }

            //最得訊號最大值當作浮動參考值
            float maxRefer = 0;

            foreach (var item in m.pallets)
            {
                if (maxRefer < (int.Parse(item.count) * float.Parse(item.rssi)))
                {
                    maxRefer = (int.Parse(item.count) * float.Parse(item.rssi));
                }
            }

            //移除低於Mask過濾值的標籤
            if (strContainerStatus == "I")
            {
                m.pallets.RemoveAll(x => (int.Parse(x.count) * float.Parse(x.rssi)) < (maxRefer * iMask / 100));
            }
            else if (strContainerStatus == "O")
            {
                m.pallets.RemoveAll(x => (int.Parse(x.count) * float.Parse(x.rssi)) < (maxRefer * iMaskOut / 100));
            }

            float kk = (maxRefer * iMask / 100);

            try
            {
                //判斷有無棧板資訊
                if (m.pallets.Count == 0)
                {
                    throw new Exception("無載貨資訊");
                }

                using (var db = new DataBase.OracleDataBase(Definition.WMSConn))
                {
                    //過濾當天已上報的棧板
                    string strRFIDList = string.Join(",", m.pallets.Select(x => "'" + x.pallet + "'"));
                    db.StrSQL = "SELECT RFID FROM " + DB_Prestr + "WMS_RFID_OK_LIST WHERE RFID IN (" + strRFIDList + ") AND TO_CHAR(CREATION_DATE,'yyyy/MM/dd') = '" + strToDay + "'";
                    var list = db.ExecuteDataTable().AsEnumerable().Select(x => x.Field <string>("RFID"));
                    m.pallets.RemoveAll(x => list.Contains(x.pallet));

                    if (m.pallets.Count > 0)
                    {
                        //判斷貨櫃進料或出料狀態(I:收料,O:出料)
                        if (strContainerStatus == "I")
                        {
                            r = POST_IN(strDockDoorID, strContainerID, strContainerStatus, m);
                        }
                        else if (strContainerStatus == "O")
                        {
                            r = POST_OUT(strDockDoorID, strContainerID, strContainerStatus, m);
                        }
                        else
                        {
                            throw new Exception("無" + strContainerID + "貨櫃資訊");
                        }
                    }
                    else
                    {
                        throw new Exception("無載貨資訊");
                    }
                }
            }
            catch (Exception ex)
            {
                //若無讀到棧板資訊則result=0
                r.result = (ex.Message == "無載貨資訊" ? "0" : "N");
                r.msg    = ex.Message;

                if (r.result == "N")
                {
                    //逐筆新增非法資料
                    using (var db = new DataBase.OracleDataBase(Definition.WMSConn))
                    {
                        foreach (var item in m.pallets)
                        {
                            db.StrSQL = @"INSERT INTO " + DB_Prestr + "WMS_RFID_NG_LIST (DOCK_DOOR_NO, RFID, ERR_MSG) VALUES('" + strDockDoorID + "', '" + item.pallet + "', '" + ex.Message + "')";
                            db.ExecuteSQL();
                        }
                    }
                }
            }
            finally
            {
                if (strContainerStatus == "I")
                {
                    AddTagLog(strDockDoorID, iMask, m, r, strData);
                }
                else if (strContainerStatus == "O")
                {
                    AddTagLog(strDockDoorID, iMaskOut, m, r, strData);
                }

                //若有正常回應,則控制字幕機
                string[] strs = new string[] { "Y", "A", "N" };
                if (strs.Contains(r.result))
                {
                    ControlMachine(strCaptionPanelIP, r.msg, 0);
                }
            }

            return(r);
        }