Esempio n. 1
0
        public void ScanKPItem(Newtonsoft.Json.Linq.JObject requestValue, Newtonsoft.Json.Linq.JObject Data, MESStationReturn StationReturn)
        {
            MESDBHelper.OleExec SFCDB = this.DBPools["SFCDB"].Borrow();
            SFCDB.BeginTrain();
            try
            {
                /*
                 * new APIInputInfo() {InputName = "SN", InputType = "STRING", DefaultValue = ""},
                 * new APIInputInfo() {InputName = "STATION", InputType = "STRING", DefaultValue = ""},
                 * new APIInputInfo() {InputName = "KPITEM", InputType = "STRING", DefaultValue = ""}
                 */
                string         strSN     = Data["SN"].ToString();
                string         station   = Data["STATION"].ToString();
                JToken         _ItemData = Data["KPITEM"];
                T_R_SN_KP      TRKP      = new T_R_SN_KP(SFCDB, DB_TYPE_ENUM.Oracle);
                List <R_SN_KP> ItemData  = new List <R_SN_KP>();
                for (int i = 0; i < _ItemData.Count(); i++)
                {
                    if (TRKP.CheckLinkByValue(_ItemData[i]["VALUE"].ToString(), SFCDB))
                    {
                        throw new Exception(_ItemData[i]["VALUE"].ToString() + " has been link on other sn!");
                    }
                    R_SN_KP I = new R_SN_KP();
                    I.ID        = _ItemData[i]["ID"].ToString();
                    I.VALUE     = _ItemData[i]["VALUE"].ToString();
                    I.MPN       = _ItemData[i]["MPN"].ToString();
                    I.PARTNO    = _ItemData[i]["PARTNO"].ToString();
                    I.SCANTYPE  = _ItemData[i]["SCANTYPE"].ToString();
                    I.ITEMSEQ   = double.Parse(_ItemData[i]["ITEMSEQ"].ToString());
                    I.SCANSEQ   = double.Parse(_ItemData[i]["SCANSEQ"].ToString());
                    I.DETAILSEQ = double.Parse(_ItemData[i]["DETAILSEQ"].ToString());

                    ItemData.Add(I);
                }
                if (ItemData.Count == 0)
                {
                    StationReturn.Status = StationReturnStatusValue.Pass;
                }

                LogicObject.SN SN = new LogicObject.SN();
                SN.Load(strSN, SFCDB, DB_TYPE_ENUM.Oracle);
                MESDataObject.Module.T_R_WO_BASE TWO = new T_R_WO_BASE(SFCDB, DB_TYPE_ENUM.Oracle);
                Row_R_WO_BASE RWO = TWO.GetWo(SN.WorkorderNo, SFCDB);

                List <R_SN_KP> snkp     = TRKP.GetKPRecordBySnIDStation(SN.ID, station, SFCDB);
                SN_KP          KPCONFIG = new SN_KP(snkp, SN.WorkorderNo, SN.SkuNo, SFCDB);

                R_SN_KP kpItem = KPCONFIG.KPS.Find(T => T.ID == ItemData[0].ID);
                if (kpItem == null)
                {
                    throw new Exception("Data Error!");
                }

                List <R_SN_KP> ConfigItem = KPCONFIG.KPS.FindAll(T => T.PARTNO == kpItem.PARTNO &&
                                                                 T.ITEMSEQ == kpItem.ITEMSEQ &&
                                                                 T.SCANSEQ == kpItem.SCANSEQ
                                                                 );

                if (ConfigItem.Count != ItemData.Count)
                {
                    throw new Exception("Data Error! ConfigItem.Count != ItemData.Count");
                }


                for (int i = 0; i < ItemData.Count; i++)
                {
                    Row_R_SN_KP item = (Row_R_SN_KP)TRKP.GetObjByID(ItemData[i].ID, SFCDB);
                    if (item.ITEMSEQ == ItemData[i].ITEMSEQ &&
                        item.SCANSEQ == ItemData[i].SCANSEQ &&
                        item.DETAILSEQ == ItemData[i].DETAILSEQ)
                    {
                        item.VALUE     = ItemData[i].VALUE;
                        item.MPN       = ItemData[i].MPN;
                        item.PARTNO    = ItemData[i].PARTNO;
                        item.EDIT_TIME = DateTime.Now;
                        item.EDIT_EMP  = LoginUser.EMP_NO;
                        SFCDB.ExecSQL(item.GetUpdateString(DB_TYPE_ENUM.Oracle));
                    }
                    else
                    {
                        throw new Exception("Data Error! 1");
                    }
                }



                StationReturn.Status = StationReturnStatusValue.Pass;
                SFCDB.CommitTrain();
            }
            catch (Exception ee)
            {
                SFCDB.RollbackTrain();
                //this.DBPools["SFCDB"].Return(SFCDB);
                StationReturn.Status      = StationReturnStatusValue.Fail;
                StationReturn.MessageCode = "MES00000037";
                StationReturn.MessagePara.Add(ee.Message);
            }
            this.DBPools["SFCDB"].Return(SFCDB);
        }
Esempio n. 2
0
        public void ScanKPItem(Newtonsoft.Json.Linq.JObject requestValue, Newtonsoft.Json.Linq.JObject Data, MESStationReturn StationReturn)
        {
            MESDBHelper.OleExec SFCDB = this.DBPools["SFCDB"].Borrow();
            SFCDB.BeginTrain();
            try
            {
                /*
                 * new APIInputInfo() {InputName = "SN", InputType = "STRING", DefaultValue = ""},
                 * new APIInputInfo() {InputName = "STATION", InputType = "STRING", DefaultValue = ""},
                 * new APIInputInfo() {InputName = "KPITEM", InputType = "STRING", DefaultValue = ""}
                 */
                string    strSN     = Data["SN"].ToString();
                string    station   = Data["STATION"].ToString();
                JToken    _ItemData = Data["KPITEM"];
                T_R_SN_KP TRKP      = new T_R_SN_KP(SFCDB, DB_TYPE_ENUM.Oracle);
                T_R_SN    t_r_sn    = new T_R_SN(SFCDB, DB_TYPE_ENUM.Oracle);

                List <R_SN_KP> ItemData = new List <R_SN_KP>();
                for (int i = 0; i < _ItemData.Count(); i++)
                {
                    //已被綁定的就不能重複綁定
                    if (TRKP.CheckLinkByValue(_ItemData[i]["VALUE"].ToString(), SFCDB))
                    {
                        throw new Exception(_ItemData[i]["VALUE"].ToString() + " has been link on other sn!");
                    }
                    R_SN r_sn = new R_SN();
                    r_sn = t_r_sn.LoadSN(_ItemData[i]["VALUE"].ToString(), SFCDB);
                    //如果KEYPART是本廠做的條碼則必須是完工狀態
                    if (r_sn != null && r_sn.COMPLETED_FLAG != "1")
                    {
                        throw new Exception(_ItemData[i]["VALUE"].ToString() + " is on " + r_sn.NEXT_STATION + ",can't completed!");
                    }
                    R_SN_KP I = new R_SN_KP();
                    I.ID        = _ItemData[i]["ID"].ToString();
                    I.VALUE     = _ItemData[i]["VALUE"].ToString();
                    I.MPN       = _ItemData[i]["MPN"].ToString();
                    I.PARTNO    = _ItemData[i]["PARTNO"].ToString();
                    I.SCANTYPE  = _ItemData[i]["SCANTYPE"].ToString();
                    I.ITEMSEQ   = double.Parse(_ItemData[i]["ITEMSEQ"].ToString());
                    I.SCANSEQ   = double.Parse(_ItemData[i]["SCANSEQ"].ToString());
                    I.DETAILSEQ = double.Parse(_ItemData[i]["DETAILSEQ"].ToString());

                    ItemData.Add(I);
                }
                if (ItemData.Count == 0)
                {
                    StationReturn.Status = StationReturnStatusValue.Pass;
                }

                LogicObject.SN SN = new LogicObject.SN();
                SN.Load(strSN, SFCDB, DB_TYPE_ENUM.Oracle);
                MESDataObject.Module.T_R_WO_BASE TWO = new T_R_WO_BASE(SFCDB, DB_TYPE_ENUM.Oracle);
                Row_R_WO_BASE RWO = TWO.GetWo(SN.WorkorderNo, SFCDB);

                List <R_SN_KP> snkp     = TRKP.GetKPRecordBySnIDStation(SN.ID, station, SFCDB);
                SN_KP          KPCONFIG = new SN_KP(snkp, SN.WorkorderNo, SN.SkuNo, SFCDB);

                R_SN_KP kpItem = KPCONFIG.KPS.Find(T => T.ID == ItemData[0].ID);
                if (kpItem == null)
                {
                    throw new Exception("Data Error!");
                }

                List <R_SN_KP> ConfigItem = KPCONFIG.KPS.FindAll(T => T.PARTNO == kpItem.PARTNO &&
                                                                 T.ITEMSEQ == kpItem.ITEMSEQ &&
                                                                 T.SCANSEQ == kpItem.SCANSEQ
                                                                 );

                if (ConfigItem.Count != ItemData.Count)
                {
                    throw new Exception("Data Error! ConfigItem.Count != ItemData.Count");
                }

                List <Row_R_SN_KP> items = new List <Row_R_SN_KP>();
                for (int i = 0; i < ItemData.Count; i++)
                {
                    Row_R_SN_KP item = (Row_R_SN_KP)TRKP.GetObjByID(ItemData[i].ID, SFCDB);
                    if (item.ITEMSEQ == ItemData[i].ITEMSEQ &&
                        item.SCANSEQ == ItemData[i].SCANSEQ &&
                        item.DETAILSEQ == ItemData[i].DETAILSEQ)
                    {
                        item.VALUE     = ItemData[i].VALUE;
                        item.MPN       = ItemData[i].MPN;
                        item.PARTNO    = ItemData[i].PARTNO;
                        item.EDIT_TIME = DateTime.Now;
                        item.EDIT_EMP  = LoginUser.EMP_NO;
                        SFCDB.ExecSQL(item.GetUpdateString(DB_TYPE_ENUM.Oracle));
                        item.AcceptChange();
                        items.Add(item);
                    }
                    else
                    {
                        throw new Exception("Data Error! 1");
                    }
                }

                for (int i = 0; i < items.Count; i++)
                {
                    var ScanTypes = SFCDB.ORM.Queryable <C_KP_Check>().Where(t => t.TYPENAME == items[i].SCANTYPE).ToList();
                    if (ScanTypes.Count > 0)
                    {
                        Assembly assembly  = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + ScanTypes[0].DLL);
                        Type     APIType   = assembly.GetType(ScanTypes[0].CLASS);
                        object   API_CLASS = assembly.CreateInstance(ScanTypes[0].CLASS);
                        var      Methods   = APIType.GetMethods();
                        var      Funs      = Methods.Where <MethodInfo>(t => t.Name == ScanTypes[0].FUNCTION);
                        if (Funs.Count() > 0)
                        {
                            Funs.ElementAt(0).Invoke(API_CLASS, new object[] { KPCONFIG, SN, items[i], items, this, SFCDB });
                        }
                    }
                }



                StationReturn.Status = StationReturnStatusValue.Pass;
                SFCDB.CommitTrain();
            }
            catch (Exception ee)
            {
                SFCDB.RollbackTrain();
                //this.DBPools["SFCDB"].Return(SFCDB);
                StationReturn.Status      = StationReturnStatusValue.Fail;
                StationReturn.MessageCode = "MES00000037";
                if (ee.InnerException != null)
                {
                    StationReturn.MessagePara.Add(ee.InnerException.Message);
                }
                else
                {
                    StationReturn.MessagePara.Add(ee.Message);
                }
            }
            this.DBPools["SFCDB"].Return(SFCDB);
        }