Ejemplo n.º 1
0
 public SimulateEntry(SessionInfo _session = null, PlanningHeadModel model = null, SimulateActionModel simModel = null)
 {
     InitializeComponent();
     this._repo = new WorkEntryRepo();
     HeadModel = model;
     SimModel = simModel;
     epiSession = _session;
 }
Ejemplo n.º 2
0
        private void SetHeader(SimulateActionModel model)
        {
            ClearContent();
            txtWorkOrderNo.DataBindings.Add("Text", model, "WorkOrderNum", false, DataSourceUpdateMode.OnPropertyChanged);
            txtMaterialWeight.DataBindings.Add("Text", model, "MaterialWeight", true, DataSourceUpdateMode.OnPropertyChanged, 1, "#,###,##0");
            txtProductWeight.DataBindings.Add("Text", model, "ProductWeight", true, DataSourceUpdateMode.OnPropertyChanged, 1, "#,###,##0");
            txtTrimingWeight.DataBindings.Add("Text", model, "TrimWeight", true, DataSourceUpdateMode.OnPropertyChanged, 1, "#,###,##0");
            txtYield.DataBindings.Add("Text", model, "Yield", true, DataSourceUpdateMode.OnPropertyChanged, 1, "##0.00");
            txtRewindWeight.DataBindings.Add("Text", model, "RewindWeight", true, DataSourceUpdateMode.OnPropertyChanged, 1, "#,###,##0");

            if (model.CheckYeild(HeadModel, model.Yield))
            {
                txtYield.BackColor = SystemColors.Control;
            }
            else
            {
                txtYield.BackColor = Color.Yellow;
            }
        }
Ejemplo n.º 3
0
        private void butCalculate_Click(object sender, EventArgs e)
        {
            //Validate check box is checked.
            if (rdoWeight.Checked || rdoLength.Checked || rdoDivision.Checked)
            {
                //When weight or length checked.
                if (rdoWeight.Checked || rdoLength.Checked)
                {
                    #region Common validation data within weight and length checked. 
                    if (string.IsNullOrEmpty(cmbCutSeq.Text.GetString()))
                    {
                        MessageBox.Show("Please fill Cut Seq. value.", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        cmbCutSeq.Focus();
                        return;
                    }

                    int decVal;
                    if (!int.TryParse(cmbCutSeq.Text, out decVal))
                    {
                        MessageBox.Show("Data type invalid.", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        cmbCutSeq.Focus();
                        cmbCutSeq.SelectAll();
                        return;
                    }

                    if (string.IsNullOrEmpty(txtExpected.Text.GetString()))
                    {
                        MessageBox.Show("Please fill Expected value.", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtExpected.Focus();
                        return;
                    }

                    decimal decExpVal;
                    if (!decimal.TryParse(txtExpected.Text, out decExpVal))
                    {
                        MessageBox.Show("Data type invalid.", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtExpected.Focus();
                        txtExpected.SelectAll();
                        return;
                    }

                    SimModel.CutSeleted = Convert.ToInt32(cmbCutSeq.Text.GetString());
                    string msg = string.Empty;
                    if (!SimModel.ValidateToCal(out msg))
                    {
                        MessageBox.Show(msg, "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        cmbCutSeq.Focus();
                        cmbCutSeq.SelectAll();
                        return;
                    }
                    #endregion

                    /*
                     * Important for case Weight and Length checked.
                     * - Length checked will be convert length expected to weight done and then call CalculateRowForWeightOption(MaterialModel).
                     * - Weight checked can be call CalculateRowForWeightOption(MaterialModel) immediately.
                     */
                    //Get index on current row.
                    int iRow = dgvMaterial.CurrentRow.Index;
                    //Get current material transaction line id.
                    int id = Convert.ToInt32(dgvMaterial.Rows[iRow].Cells["transactionlineid"].Value.ToString()).GetInt();
                    //Get using status on current row.
                    bool usedflag = Convert.ToBoolean(dgvMaterial.Rows[iRow].Cells["usedflag"].Value.ToString()).GetBoolean();
                    //Get material serial No on current row. 
                    string article = dgvMaterial.Rows[iRow].Cells["article"].Value.ToString().GetString().Trim();

                    //Get Material Row by selected.
                    var mat = _repo.GetMaterial(id);

                    //New object instant.
                    //IEnumerable<SimulateModel> line = new List<SimulateModel>();
                    //Get calculated cutting line by [CutDivision, MaterialSerialNo, CalculateFlag == true] parameter, this line will be to verify weight/length remain balance.
                    //line = SimModel.Cuttings.Where(i => i.CutDiv.Equals(SimModel.CutSeleted) && i.MaterialSerialNo.GetString() == article && i.CalculatedFlag.GetBoolean() == true).ToList();

                    //***Length option checked.
                    if (rdoLength.Checked)
                    {
                        //Simulate option = 1 is calculate by Length.
                        SimModel.SimulateOption = 1;
                        //Keep expected value into 'SimModel.Expected' from TextBox.
                        SimModel.Expected = Convert.ToDecimal(txtExpected.Text.GetString());

                        //decimal usingLengthM = Convert.ToDecimal(dgvMaterial.Rows[iRow].Cells["usingLengthM"].Value.ToString()).GetDecimal();
                        decimal LengthM = Convert.ToDecimal(dgvMaterial.Rows[iRow].Cells["LengthM"].Value.ToString()).GetDecimal();
                        //Get Length remaining on current row selected.
                        decimal RemainLengthM = Convert.ToDecimal(dgvMaterial.Rows[iRow].Cells["RemainLengthM"].Value.ToString()).GetDecimal();

                        #region Validation Length remaining for material partial used.
                        //If current material selected is used and 
                        if (usedflag) // && line.ToList().Count == 0)
                        {
                            if (RemainLengthM < SimModel.Expected)
                            {
                                MessageBox.Show("Expected value must Less than or Equals material length(M).", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                txtExpected.Focus();
                                txtExpected.SelectAll();
                                return;
                            }
                        }
                        else
                        {
                            if (LengthM < SimModel.Expected)
                            {
                                MessageBox.Show("Expected value must Less than or Equals material length(M).", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                txtExpected.Focus();
                                txtExpected.SelectAll();
                                return;
                            }
                        }
                        #endregion

                        //Keep variable expected value and convert value to decimal.
                        decimal d = Convert.ToDecimal(txtExpected.Text.GetString());

                        //Calculate all rows for material and cutting grid by Simulate header.
                        //SimModel.CalculateRowForLegnthOption(mat);
                        //Convert Length to Weight and keep [Weight value] for calculate same weight option checked.
                        SimModel.Expected = (mat.Weight * d) / mat.LengthM;                        
                    }

                    //***Weight option checked.
                    if (rdoWeight.Checked)
                    {
                        //Simulate option = 1 is calculate by Weight.
                        SimModel.SimulateOption = 0;
                        //Keeping [Weight value] for calculate.
                        SimModel.Expected = Convert.ToDecimal(txtExpected.Text.GetString());
                    }

                    //Keeping [Cutting value] for calculate.
                    SimModel.CutSeleted = Convert.ToInt32(cmbCutSeq.Text.GetString());

                    //Keeping weight value from material grid.
                    decimal weight = Convert.ToDecimal(dgvMaterial.Rows[iRow].Cells["weight"].Value.ToString()).GetDecimal();
                    //Keeping remain weight value from material grid.
                    decimal remainWeight = Convert.ToDecimal(dgvMaterial.Rows[iRow].Cells["remainWeight"].Value.ToString()).GetDecimal();

                    #region Validation Weight remaining for material partial used.
                    if (usedflag)// && line.ToList().Count == 0)
                    {
                        if (remainWeight < SimModel.Expected)
                        {
                            MessageBox.Show("Expected value must Less than or Equals material weight.", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            txtExpected.Focus();
                            txtExpected.SelectAll();
                            return;
                        }
                    }
                    else
                    {
                        if (weight < SimModel.Expected)
                        {
                            MessageBox.Show("Expected value must Less than or Equals material weight.", "Warnning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            txtExpected.Focus();
                            txtExpected.SelectAll();
                            return;
                        }
                    }
                    #endregion

                    //Calculate after data preparation in case Weight and Length checked.
                    SimModel.CalculateRowForWeightOption(mat);
                    SimModel.SumTrimmingWeight(HeadModel);
                }
                else if (rdoDivision.Checked)
                {
                    SimModel.SimulateOption = 2;
                    SimModel.Expected = Convert.ToDecimal(txtExpected.Text.GetString());
                    if (_repo.ClearSimulateLines(HeadModel.WorkOrderID))
                    {
                        SimulateActionModel simModel = new SimulateActionModel();
                        simModel.WorkOrderID = HeadModel.WorkOrderID;
                        simModel.WorkOrderNum = HeadModel.WorkOrderNum;
                        simModel.MaterialWeight = HeadModel.InputWeight;
                        simModel.ProductWeight = HeadModel.OutputWeight;
                        simModel.Yield = HeadModel.Yield;
                        simModel.TrimWeight = HeadModel.CuttingDesign.Where(i => i.Status.Equals("S")).Sum(i => i.TotalWeight);
                        simModel.Cuttings.Where(i => i.WorkOrderID.Equals(HeadModel.WorkOrderID));

                        SimModel.Cuttings = _repo.InsertSimulate(epiSession, HeadModel, Convert.ToInt32(SimModel.Expected)).ToList();
                        SimModel.Materials = HeadModel.Materials.ToList();
                    }
                }

                ListMaterialGrid(SimModel.Materials);
                ListSimulateGrid(SimModel.Cuttings);
                SetHeader(SimModel);
            }
            else
            {
                MessageBox.Show("Please select option for calculate.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 4
0
        private void butSimulate_Click(object sender, EventArgs e)
        {
            if (HeaderContent.ProcessLine.ResourceGrpID == "S")
            {
                SimulateActionModel simModel = new SimulateActionModel();
                simModel.WorkOrderID = HeaderContent.WorkOrderID;
                simModel.WorkOrderNum = HeaderContent.WorkOrderNum;
                simModel.MaterialWeight = HeaderContent.InputWeight;
                simModel.ProductWeight = HeaderContent.OutputWeight;
                simModel.Yield = HeaderContent.Yield;
                simModel.TrimWeight = HeaderContent.CuttingDesign.Where(i => i.Status.Equals("S")).Sum(i => i.TotalWeight);
                simModel.Cuttings = _repo.GetSimulateAll(HeaderContent.WorkOrderID).ToList();
                simModel.Materials = HeaderContent.Materials.ToList();
                using (SimulateEntry frm = new SimulateEntry(epiSession, HeaderContent, simModel))
                {
                    frm.ShowDialog();
                    HeaderContent = frm.HeadModel;
                }
            }

            SetHeadContent(HeaderContent);
            ListMaterialGrid(HeaderContent.Materials);
            ListCuttingGrid(HeaderContent.CuttingDesign);
            ListCoilBackGrid(HeaderContent.CoilBacks);
            dgvMaterial.EndEdit();
        }
Ejemplo n.º 5
0
        private void tbutSimulate_Click(object sender, EventArgs e)
        {
            if (HeaderContent.Completed == 1)
            {
                MessageBox.Show("This work order has completed process, can't re-simulate.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (HeaderContent.GenSerialFlag == 1)
            {
                MessageBox.Show("This work order has generated serial, can't re-simulate.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (HeaderContent.ProcessLine.ResourceGrpID == "S")
            {
                //Simulated Complete.
                var resExisting = _repo.GetSimulateAll(HeaderContent.WorkOrderID);
                if (resExisting.ToList().Count > 0)
                {
                    DialogResult diaResult = MessageBox.Show("Simulate line has already, are you sure to clear all.", "Question.", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (diaResult == DialogResult.Yes)
                    {
                        _repo.ClearSimulateLines(HeaderContent.WorkOrderID);
                    }
                    else
                    {
                        return;
                    }
                }
                SimulateActionModel simModel = new SimulateActionModel();
                simModel.WorkOrderID = HeaderContent.WorkOrderID;
                simModel.WorkOrderNum = HeaderContent.WorkOrderNum;
                simModel.MaterialWeight = HeaderContent.InputWeight;
                simModel.ProductWeight = HeaderContent.OutputWeight;
                simModel.RewindWeight = HeaderContent.RewindWeight;
                simModel.Yield = HeaderContent.Yield;
                simModel.TrimWeight = HeaderContent.CuttingDesign.Where(i => i.Status.Equals("S")).Sum(i => i.TotalWeight);

                simModel.Cuttings = _repo.InsertSimulate(epiSession, HeaderContent).ToList();
                simModel.Materials = HeaderContent.Materials.ToList();
                using (SimulateEntry frm = new SimulateEntry(epiSession, HeaderContent, simModel))
                {
                    frm.ShowDialog();
                    HeaderContent = frm.HeadModel;
                }

                SetHeadContent(HeaderContent);
                ListMaterialGrid(HeaderContent.Materials);
                ListCuttingGrid(HeaderContent.CuttingDesign);
                ListCoilBackGrid(HeaderContent.CoilBacks);
                tbutCalculate_Click(sender, e);
                //tbutSave_Click(sender, e);
                HeaderContent.SimulateFlag = 1;
            }
            else if (HeaderContent.ProcessLine.ResourceGrpID == "R")
            {
                SimulateReshearHeadModel simModel = new SimulateReshearHeadModel();
                simModel.Materials = HeaderContent.Materials.ToList();
                simModel.Cuttings = HeaderContent.CuttingDesign.ToList();
                simModel.WorkOrderID = HeaderContent.WorkOrderID;
                simModel.WorkOrderNum = HeaderContent.WorkOrderNum;

                using (SimulateReShear frm = new SimulateReShear(epiSession, HeaderContent, simModel))
                {
                    frm.ShowDialog();
                    HeaderContent = frm.HeadModel;
                }
            }
        }
Ejemplo n.º 6
0
        public void CalculateRow(SimulateActionModel head, MaterialModel mat)
        {
            //Fix bug in case Materials is null.
            //if (head.SimulateOption == 0)
            //{
            decimal widthMat = 0;
            decimal cutMax = 0;
            widthMat = mat.Width;
            cutMax = head.Cuttings.Max(i => i.CutDiv);
            UnitWeight = Math.Round(CalUnitWgtByUsingWgt(head.Expected, widthMat, Width), 2);
            TotalWeight = UnitWeight * Stand;
            LengthM = Math.Round(CalLengthMeter(UnitWeight, Width, Thick, Gravity, FrontPlate, BackPlate), 0);
            //}
            //else if (head.SimulateOption == 1)
            //{
            //    LengthM = mat.UsingLengthM;
            //    UnitWeight = (mat.Weight * LengthM) / mat.LengthM;
            //}

            CalculatedFlag = true;
            MCSSNum = mat.MCSSNo;
            TransactionLineID = mat.TransactionLineID;
            MaterialSerialNo = mat.SerialNo;
        }