Esempio n. 1
0
 public EkanbanHisControl(EKanbanHis ekanbanHis, EKanbanDevice eKanbanDevice, IDbName _database)
 {
     InitializeComponent();
     EKanbanHis       = new EKanbanHis();
     EKanbanHis       = ekanbanHis;
     eKanbanTaskQuery = new EKanbanTaskQuery(_database);
     SysHistoryQuery  = new SysHistoryQuery(_database);
     lbCartName.Text  = eKanbanDevice.Name;
 }
Esempio n. 2
0
 public bool UpdateEKanbanHis(EKanbanHis _ekanbanHis)
 {
     try
     {
         using (HistoryContext = new HistoryContext(database))
         {
             HistoryContext.Entry(_ekanbanHis).State = EntityState.Modified;
             HistoryContext.SaveChanges();
             return(true);
         }
     }
     catch { return(false); }
 }
Esempio n. 3
0
 public bool AddNewEKanbanHisotry(EKanbanHis _ekanbanHis)
 {
     try
     {
         using (HistoryContext = new HistoryContext(database))
         {
             HistoryContext.EKanbanHis.Add(_ekanbanHis);
             HistoryContext.SaveChanges();
             return(true);
         }
     }
     catch { return(false); }
 }
Esempio n. 4
0
        /// <summary>
        /// Thêm thông tin vào Ekanban
        /// </summary>
        private void AddSequenceToEKanban()
        {
            if (SelectedEKanbanDevice == null || SelectedEKanbanDevice.id == 0)
            {
                MessageBox.Show("An Error orcured while adding Sequence to EKanban.\r\nError: Missing Ekanban device.", "Message",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var ekbLoading = EKanbanTaskQuery.GetEKanbanLoading(SelectedSequence.id);

            if (ekbLoading != null)
            {
                MessageBox.Show("An Error orcured while adding Sequence to EKanban.\r\nError: The sequence is already added.", "Message",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (SelectedOriginalPo.id == 0 || SelectedSequence.id == 0 || SelectedSchedule.id == 0)
            {
                MessageBox.Show("An Error orcured while adding Sequence to EKanban.\r\nError: Missing data.", "Message",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var dresult = MessageBox.Show("Make sure you want to continue?", "Question",
                                          MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (dresult != DialogResult.Yes)
            {
                return;
            }

            int           action  = 0;
            SysActionCode SysCode = SysActionCode.UNKNOW;

            EKanbanHis EkanbanHis = new EKanbanHis();

            if (SelectedEKanbanInterface == null)
            {
                action = 0;
            }
            else
            {
                if (SelectedEKanbanInterface.id != 0)
                {
                    SysCode    = (SysActionCode)SelectedEKanbanInterface.SysActionCode;
                    EkanbanHis = SysHistoryQuery.GetEKanbanHistory(SelectedEKanbanInterface);
                }
            }


            switch (SysCode)
            {
            case SysActionCode.SEQUENCE_PREPARING:
            case SysActionCode.EKANBAN_ADD_NEW_ITEM:
                dresult = MessageBox.Show("EKanban is holding data, do you want to continue?", "Message",
                                          MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                if (dresult != DialogResult.Yes)
                {
                    return;
                }
                action = 1;
                break;

            case SysActionCode.SEQUENCE_CONFORM:
            case SysActionCode.EKANBAN_CONFIRM_ITEM:
                action = 0;
                break;

            default:
                break;
            }

            switch (action)
            {
            case 0:     // add new interface
                List <EKanbanComponent> eKanbanComponent = new List <EKanbanComponent>();
                foreach (var item in SelectShoeComponent)
                {
                    if (item.AddToEkanban)
                    {
                        eKanbanComponent.Add(new EKanbanComponent
                        {
                            ShoeComponent_Id = item.Id,
                            CuttingType_Id   = item.CuttingType.id,
                        });
                    }
                }
                // add new interface
                EKanbanInterface eKanbanInterface = new EKanbanInterface
                {
                    LastUpdate        = DateTime.Now,
                    PO                = GetShortPoNumber(SelectedSchedule.PoNumber),
                    Line              = SelectedScheduleLine,
                    EKanbanDevice_Id  = SelectedEKanbanDevice.id,
                    POqty             = SelectedSchedule.Quantity.ToString(),
                    SysActionCode     = (int)SysActionCode.EKANBAN_ADD_NEW_ITEM,
                    EkanbanComponents = new List <EKanbanComponent>(eKanbanComponent),
                    SequenceNo        = SelectedSequence.SequenceNo.ToString(),
                    CartQty           = SelectedSequence.Quantity.ToString(),

                    EKanbanLoadings = new List <EKanbanLoading>
                    {
                        new EKanbanLoading
                        {
                            SysActionCode       = (int)SysActionCode.SEQUENCE_PREPARING,
                            OriginalPo_Id       = SelectedOriginalPo.id,
                            OriginalSequence_Id = SelectedSequence.id,
                            LastUpdate          = DateTime.Now,
                            SequenceQty         = SelectedSequence.Quantity
                        }
                    }
                };

                if (EKanbanTaskQuery.AddNewEKanbanInterface(eKanbanInterface))
                {
                    var inf1 = EKanbanTaskQuery.FindEKanbanInterface(eKanbanInterface.id);

                    string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(inf1);
                    EkanbanHis = new EKanbanHis
                    {
                        EKanbanInterface_Id = eKanbanInterface.id,
                        EKanbanDevice_Id    = SelectedEKanbanDevice.id,
                        DateTime            = DateTime.Now,
                        ProductionLine_Id   = SelectedSchedule.ProductionLine_Id,
                        Data = jsonStr,
                    };

                    MessageBox.Show("Add new Ekanban Interface successfully", "Message");

                    bool success = SysHistoryQuery.AddNewEKanbanHisotry(EkanbanHis);

                    if (!success)
                    {
                        MessageBox.Show("Add new Ekanban history record error", "Message");
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("An error orcured while adding new Po to Ekanban.\r\nError: Failed to add new Ekanban interface to database.", "Message",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                break;

            case 1:     // update interface

                EKanbanLoading eKanbanLoading = new EKanbanLoading
                {
                    EKanbanInterface_Id = SelectedEKanbanInterface.id,
                    SysActionCode       = (int)SysActionCode.SEQUENCE_PREPARING,
                    OriginalPo_Id       = SelectedOriginalPo.id,
                    OriginalSequence_Id = SelectedSequence.id,
                    LastUpdate          = DateTime.Now,
                    SequenceQty         = SelectedSequence.Quantity,
                };

                bool exp1 = EKanbanTaskQuery.AddNewEKanbanLoading(eKanbanLoading);

                if (!exp1)
                {
                    MessageBox.Show("An error orcured while adding new Po to Ekanban.\r\nError: Failed to add EkanbanLoading to database.", "Message",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                SelectedEKanbanInterface.PO         += $",{GetShortPoNumber(SelectedSchedule.PoNumber)}";
                SelectedEKanbanInterface.SequenceNo += $",{SelectedSequence.SequenceNo}";
                SelectedEKanbanInterface.POqty      += $",{SelectedSchedule.Quantity}";
                SelectedEKanbanInterface.CartQty    += $",{SelectedSequence.Quantity}";
                SelectedEKanbanInterface.LastUpdate  = DateTime.Now;
                bool exp2 = EKanbanTaskQuery.UpdateEKanbanInterface(SelectedEKanbanInterface);

                EKanbanInterface inf2 = EKanbanTaskQuery.FindEKanbanInterface(SelectedEKanbanInterface.id);

                var    his      = SysHistoryQuery.GetEKanbanHistory(SelectedEKanbanInterface);
                string jsonStr2 = Newtonsoft.Json.JsonConvert.SerializeObject(inf2);
                his.Data     = jsonStr2;
                his.DateTime = DateTime.Now;
                SysHistoryQuery.UpdateEKanbanHis(his);



                if (exp1 && exp2)
                {
                    MessageBox.Show("Add new Po to Ekanban succeesfully", "Message");
                }

                if (!exp2)
                {
                    MessageBox.Show("An error orcured while adding new Po to Ekanban.\r\nError: Failed to update Ekanban interface.", "Message");
                    EKanbanTaskQuery.DeleteEKanbanLoading(eKanbanLoading);
                    return;
                }

                // update interface
                break;
            }

            UpdateSelectedSchedule();

            UpdateSelectedEkanbanDevice();

            UpdateSelectedOriginalSequence();

            AddNewStockMeasure();

            AddNewHistory(EkanbanHis.id);
        }