Пример #1
0
        private void dgvCutting_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (OrderCompleted()) return;

            OrderHeadModel result = new OrderHeadModel();
            int i; decimal d; string riskFlag = string.Empty; string msg = string.Empty;
            string colName = dgvCutting.Columns[e.ColumnIndex].Name;
            string lineId = dgvCutting.Rows[e.RowIndex].Cells["lineid"].Value.GetString();
            string resultValue = dgvCutting.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.GetString();
            bool changeState = false;

            CutDesignModel rowData = new CutDesignModel();
            rowData = (from item in HeaderContent.CuttingDesign
                       where item.LineID == Convert.ToInt32(lineId)
                       select item).FirstOrDefault();
            rowData.CompleteRow = false;
            switch (colName)
            {
                case "sono":

                    #region Verify S/O No.

                    if (HeaderContent.Materials.ToList().Count == 0) HeaderContent.BussinessType = "";
                    if (HeaderContent.CuttingDesign.ToList().Count == 1) HeaderContent.BussinessType = "";

                    if (!string.IsNullOrEmpty(resultValue) && rowData.SONo != resultValue)
                    {
                        var resultTmp = _repoSale.GetOrderHeader(HeaderContent, resultValue).ToList();

                        dgvCutting.Rows[e.RowIndex].Cells["soline"].Value = string.Empty;
                        if (resultTmp.ToList().Count == 0)
                        {
                            var soResult = _repoSale.GetOrderHeader(HeaderContent);
                            using (OrderHeadDialog frm = new OrderHeadDialog(epiSession, soResult))
                            {
                                frm.ShowDialog();
                                result = frm._selected;
                                if (result == null)
                                {
                                    dgvCutting.Rows[e.RowIndex].Cells["sono"].Value = string.Empty;
                                    dgvCutting.Rows[e.RowIndex].Cells["soline"].Value = string.Empty;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            result = resultTmp.FirstOrDefault();
                        }

                        //Set header value.
                        HeaderContent.OrderType = result.OrderType;
                        if (!string.IsNullOrEmpty(result.OrderNumber))
                        {
                            HeaderContent.CuttingDesign = addSOLine(Convert.ToInt32(lineId), result.OrderNumber);

                            rowData = (from item in HeaderContent.CuttingDesign
                                       where item.LineID == Convert.ToInt32(lineId)
                                       select item).FirstOrDefault();

                            dgvCutting.Rows[e.RowIndex].Cells["sono"].Value = rowData.SONo;
                            dgvCutting.Rows[e.RowIndex].Cells["customer"].Value = result.CustID;
                            dgvCutting.Rows[e.RowIndex].Cells["soline"].Value = rowData.SOLine;
                            dgvCutting.Rows[e.RowIndex].Cells["norno"].Value = rowData.NORNum;
                            dgvCutting.Rows[e.RowIndex].Cells["commodity1"].Value = rowData.CommodityCode;
                            dgvCutting.Rows[e.RowIndex].Cells["spec1"].Value = rowData.SpecCode;
                            dgvCutting.Rows[e.RowIndex].Cells["coating1"].Value = rowData.CoatingCode;
                            dgvCutting.Rows[e.RowIndex].Cells["thick1"].Value = rowData.Thick;
                            dgvCutting.Rows[e.RowIndex].Cells["width1"].Value = rowData.Width;
                            dgvCutting.Rows[e.RowIndex].Cells["length1"].Value = rowData.Length;
                            dgvCutting.Rows[e.RowIndex].Cells["status1"].Value = "";
                            dgvCutting.Rows[e.RowIndex].Cells["soweight"].Value = rowData.SOWeight;
                            dgvCutting.Rows[e.RowIndex].Cells["soqty"].Value = rowData.SOQuantity;
                            dgvCutting.Rows[e.RowIndex].Cells["qtyPack1"].Value = rowData.QtyPack;
                            dgvCutting.Rows[e.RowIndex].Cells["pack"].Value = rowData.Pack;
                            dgvCutting.Rows[e.RowIndex].Cells["bt1"].Value = rowData.BussinessType;
                        }
                        else
                        {
                            dgvCutting.Rows[e.RowIndex].Cells["sono"].Value = rowData.SONo;
                        }
                    }

                    #endregion Verify S/O No.

                    break;

                case "soline":
                    changeState = (rowData.SOLine != Convert.ToInt32(resultValue));
                    rowData.SOLine = Convert.ToInt32(string.IsNullOrEmpty(resultValue) ? "0" : resultValue);
                    break;

                case "width1":
                    if (!decimal.TryParse(resultValue, out d))
                    {
                        //e.Cancel = true;
                        return;
                    }
                    changeState = (rowData.Width != Convert.ToDecimal(resultValue));
                    rowData.Width = Convert.ToDecimal(string.IsNullOrEmpty(resultValue) ? "0M" : resultValue);
                    break;

                case "length1":
                    if (!decimal.TryParse(resultValue, out d))
                    {
                        return;
                    }
                    changeState = (rowData.Length != Convert.ToDecimal(resultValue));
                    rowData.Length = Convert.ToDecimal(string.IsNullOrEmpty(resultValue) ? "0M" : resultValue);
                    break;

                case "status1":
                    changeState = (rowData.Status != resultValue);
                    if (changeState)
                    {
                        if (HeaderContent.ProcessLine.ResourceGrpID == "L")
                        {
                            if (resultValue == "F" && !string.IsNullOrEmpty(rowData.NORNum))
                            {
                                dgvCutting.Rows[e.RowIndex].Cells["length1"].ReadOnly = true;
                            }
                            else
                            {
                                dgvCutting.Rows[e.RowIndex].Cells["length1"].ReadOnly = false;
                            }
                        }
                        else if (HeaderContent.ProcessLine.ResourceGrpID == "S")
                        {
                            if (resultValue == "S" && !string.IsNullOrEmpty(rowData.NORNum))
                            {
                                dgvCutting.Rows[e.RowIndex].Cells["width1"].ReadOnly = true;
                            }
                            else
                            {
                                dgvCutting.Rows[e.RowIndex].Cells["width1"].ReadOnly = false;
                            }
                        }
                    }
                    rowData.Status = resultValue;
                    break;

                case "stand":
                    if (!int.TryParse(resultValue, out i))
                    {
                        return;
                    }
                    changeState = (rowData.Stand != Convert.ToInt32(resultValue));
                    rowData.Stand = Convert.ToInt32(resultValue);
                    break;

                case "cutdiv":
                    if (!int.TryParse(resultValue, out i))
                    {
                        return;
                    }
                    changeState = (rowData.CutDivision != Convert.ToInt32(resultValue));
                    rowData.CutDivision = Convert.ToInt32(resultValue);
                    break;

                case "note1":
                    changeState = (rowData.Note != resultValue);
                    rowData.Note = resultValue;
                    break;

                case "soqty":
                    changeState = (rowData.SOQuantity != Convert.ToDecimal(resultValue));
                    rowData.SOQuantity = Convert.ToDecimal(resultValue);
                    break;

                case "calqty":
                    changeState = (rowData.CalQuantity != Convert.ToDecimal(resultValue));
                    rowData.CalQuantity = Convert.ToDecimal(resultValue);
                    break;

                case "qtyPack1":
                    changeState = (rowData.QtyPack != Convert.ToDecimal(resultValue));
                    rowData.QtyPack = Convert.ToDecimal(resultValue);
                    break;
            }

            if (changeState)
            {
                rowData.CalculateRows(HeaderContent);
                bool validRow = rowData.ValidateByRow(HeaderContent, out riskFlag, out msg);
                dgvCutting.Rows[e.RowIndex].Cells["rowValidated"].Value = validRow;
                if (!validRow)
                {
                    if (riskFlag == "ERROR")
                    {
                        DialogResult diaResult = MessageBox.Show(msg, "Row validate error!.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                //Set rial time to change weight by row.
                dgvCutting.Rows[e.RowIndex].Cells["unitweight1"].Value = rowData.UnitWeight;
                dgvCutting.Rows[e.RowIndex].Cells["totalweight"].Value = rowData.TotalWeight;
                dgvCutting.Rows[e.RowIndex].Cells["totallength"].Value = rowData.TotalLength;
                rowData.CompleteRow = validRow;
                HeaderContent.CuttingDesign = _repo.SaveLineCutting(epiSession, HeaderContent, rowData).ToList();
                SetHeadContent(HeaderContent);
                ListMaterialGrid(HeaderContent.Materials);
            }
        }
Пример #2
0
 public bool DeleteCutting(SessionInfo _session, CutDesignModel model, out string msg)
 {
     msg = "";
     try
     {
         string sql = string.Format(@"DELETE FROM ucc_pln_CuttingDesign WHERE LineID = {0}" + Environment.NewLine, model.LineID);
         sql += string.Format(@"DELETE FROM ucc_pln_LevellerSimulateTmp WHERE CuttingLineID = {0}" + Environment.NewLine, model.LineID);
         sql += string.Format(@"DELETE FROM ucc_pln_Simulate WHERE CuttingLineID = {0}" + Environment.NewLine, model.LineID);
         Repository.Instance.ExecuteWithTransaction(sql, "Delete Cutting");
         return true;
     }
     catch (Exception ex)
     {
         msg = ex.Message;
         return false;
     }
 }
Пример #3
0
        private void tbutNewCutting_Click(object sender, EventArgs e)
        {
            CutDesignModel model = new CutDesignModel();

            if (HeaderContent.Materials.ToList().Count == 0)
            {
                model.Status = "S";
                model.Stand = 1;
                model.CutDivision = 1;
                model.DeliveryDate = DateTime.Now;
                model.BussinessType = string.IsNullOrEmpty(HeaderContent.BussinessType.GetString()) ? "" : HeaderContent.BussinessType;
            }
            else
            {
                var result = (from item in HeaderContent.Materials
                              select item).FirstOrDefault();

                model.Status = "S";
                model.DeliveryDate = DateTime.Now;
                model.BussinessType = string.IsNullOrEmpty(HeaderContent.BussinessType.GetString()) ? "" : HeaderContent.BussinessType;
                model.Possession = string.IsNullOrEmpty(HeaderContent.Possession.GetString()) ? 0 : Convert.ToInt32(HeaderContent.Possession);
                model.CommodityCode = result.CommodityCode;
                model.SpecCode = result.SpecCode;
                model.CoatingCode = result.CoatingCode;
                model.Thick = result.Thick;
                model.Width = result.Width;
                model.Length = result.Length;
                model.Stand = 1;
                model.CutDivision = 1;
                model.UnitWeight = HeaderContent.UsingWeight;
                model.TotalWeight = HeaderContent.UsingWeight;
                model.CustID = result.CustID;
                model.BussinessType = result.BussinessType;
                model.ProductStatus = string.IsNullOrEmpty(result.ProductStatus.GetString()) ? 0 : Convert.ToInt32(result.ProductStatus);
            }

            HeaderContent.CuttingDesign = _repo.SaveLineCutting(epiSession, HeaderContent, model).ToList();
            ListCuttingGrid(HeaderContent.CuttingDesign);
            //SetPermissCuttingDesign();
            //dgvCutting.Columns["thick1"].ReadOnly = false;
            //dgvCutting.Columns["width1"].ReadOnly = false;
            //dgvCutting.Columns["length1"].ReadOnly = false;
        }
Пример #4
0
        public IEnumerable<CutDesignModel> SaveLineCutting(SessionInfo _session, PlanningHeadModel head, CutDesignModel data)
        {
            string sql = string.Format(@"IF NOT EXISTS
									    (
										    SELECT * FROM ucc_pln_CuttingDesign (NOLOCK)
										    WHERE LineID = {34}
									    )
                                        BEGIN
                                            INSERT INTO ucc_pln_CuttingDesign
                                                       (Company
                                                       ,Plant
                                                       ,WorkOrderID
                                                       ,TransactionLineID
                                                       ,CutSeq
                                                       ,SONo
                                                       ,SOLine
                                                       ,NORNum
                                                       ,CommodityCode
                                                       ,SpecCode
                                                       ,CoatingCode
                                                       ,Thick
                                                       ,Width
                                                       ,Length
                                                       ,Status
                                                       ,Stand
                                                       ,CutDivision
                                                       ,UnitWeight
                                                       ,TotalWeight
                                                       ,CustID
                                                       ,EndUserCode
                                                       ,DestinationCode
                                                       ,QtyPack
                                                       ,Pack
                                                       ,SOWeight
                                                       ,SOQuantity
                                                       ,CalQuantity
                                                       ,DeliveryDate
                                                       ,BussinessType
                                                       ,Possession
                                                       ,ProductStatus
                                                       ,Description
                                                       ,Note
                                                       ,CreationDate
                                                       ,LastUpdateDate
                                                       ,CreatedBy
                                                       ,UpdatedBy, TotalLength, CompletedRow, QtyPerMaterial, Direction)
                                                 VALUES
                                                       ( N'{0}' --<Company, nvarchar(8),>
                                                       , N'{1}' --<Plant, nvarchar(8),>
                                                       , {2} --<WorkOrderID, bigint,>
                                                       , {3} --<TransactionLineID, bigint,>
                                                       , {4} --<CutSeq, int,>
                                                       , N'{5}' --<SONo, nvarchar(30),>
                                                       , {6} --<SOLine, int,>
                                                       , N'{7}' --<NORNum, nvarchar(100),>
                                                       , N'{8}' --<CommodityCode, nvarchar(30),>
                                                       , N'{9}' --<SpecCode, nvarchar(30),>
                                                       , N'{10}' --<CoatingCode, nvarchar(30),>
                                                       , {11} --<Thick, decimal(20,9),>
                                                       , {12} --<Width, decimal(20,9),>
                                                       , {13} --<Length, decimal(20,9),>
                                                       , N'{14}' --<Status, nvarchar(20),>
                                                       , {15} --<Stand, int,>
                                                       , {16} --<CutDivision, int,>
                                                       , {17} --<UnitWeight, decimal(20,9),>
                                                       , {18} --<TotalWeight, decimal(20,9),>
                                                       , N'{19}' --<CustID, nvarchar(20),>
                                                       , N'{20}' --<EndUserCode, nvarchar(20),>
                                                       , N'{21}' --<DestinationCode, nvarchar(20),>
                                                       , {22} --<QtyPack, decimal(20,9),>
                                                       , {23} --<Pack, decimal(20,9),>
                                                       , {24} --<SOWeight, decimal(20,9),>
                                                       , {25} --<SOQuantity, decimal(20,9),>
                                                       , {26} --<CalQuantity, decimal(20,9),>
                                                       , CONVERT(DATETIME, '{27}',103) --<DeliveryDate, datetime,>
                                                       , N'{28}' --<BussinessType, nvarchar(50),>
                                                       , {29} --<Procession, int,>
                                                       , {30} --<ProductStatus, int,>
                                                       , N'{31}' --<Description, varchar(max),>
                                                       , N'{32}' --<Note, varchar(max),>
                                                       , GETDATE() --<CreationDate, datetime,>
                                                       , GETDATE() --<LastUpdateDate, datetime,>
                                                       , N'{33}' --<CreatedBy, varchar(45),>
                                                       , N'{33}' --<UpdatedBy, varchar(45),>
                                                       , {35}  --<TotalLength, Decimal(20,9)>
                                                       , {36}  --<CompletedRow, int>
                                                       , {37}  --<QtyPerMaterial, int>
                                                       , '{38}'  --<Direction, nchar(10)>
		                                               )
                                            END
                                        ELSE
                                            BEGIN
                                                UPDATE ucc_pln_CuttingDesign
                                                   SET Company = N'{0}'  --<Company, nvarchar(8),>
                                                      ,Plant = N'{1}'  --<Plant, nvarchar(8),>
                                                      ,WorkOrderID = {2}  --<WorkOrderID, bigint,>
                                                      ,TransactionLineID = {3}  --<TransactionLineID, bigint,>
                                                      ,CutSeq = {4}  --<CutSeq, int,>
                                                      ,SONo = N'{5}'  --<SONo, nvarchar(30),>
                                                      ,SOLine = {6}  --<SOLine, int,>
                                                      ,NORNum = N'{7}'  --<NORNum, nvarchar(100),>
                                                      ,CommodityCode = N'{8}'  --<CommodityCode, nvarchar(30),>
                                                      ,SpecCode = N'{9}'  --<SpecCode, nvarchar(30),>
                                                      ,CoatingCode = N'{10}'  --<CoatingCode, nvarchar(30),>
                                                      ,Thick = {11}  --<Thick, decimal(20,9),>
                                                      ,Width = {12}  --<Width, decimal(20,9),>
                                                      ,Length = {13}  --<Length, decimal(20,9),>
                                                      ,Status = N'{14}'  --<Status, nvarchar(20),>
                                                      ,Stand = {15}  --<Stand, int,>
                                                      ,CutDivision = {16}  --<CutDivision, int,>
                                                      ,UnitWeight = {17}  --<UnitWeight, decimal(20,9),>
                                                      ,TotalWeight = {18}  --<TotalWeight, decimal(20,9),>
                                                      ,CustID = N'{19}'  --<CustID, nvarchar(20),>
                                                      ,EndUserCode = N'{20}'  --<EndUserCode, nvarchar(20),>
                                                      ,DestinationCode = N'{21}'  --<DestinationCode, nvarchar(20),>
                                                      ,QtyPack = {22}  --<QtyPack, decimal(20,9),>
                                                      ,Pack = {23}  --<Pack, decimal(20,9),>
                                                      ,SOWeight = {24}  --<SOWeight, decimal(20,9),>
                                                      ,SOQuantity = {25}  --<SOQuantity, decimal(20,9),>
                                                      ,CalQuantity = {26}  --<CalQuantity, decimal(20,9),>
                                                      ,DeliveryDate = CONVERT(DATETIME, '{27}',103)  --<DeliveryDate, datetime,>
                                                      ,BussinessType = N'{28}'  --<BussinessType, nvarchar(50),>
                                                      ,Possession = {29}  --<Procession, int,>
                                                      ,ProductStatus = {30}  --<ProductStatus, int,>
                                                      ,Description = N'{31}'  --<Description, varchar(max),>
                                                      ,Note = N'{32}'  --<Note, varchar(max),>
                                                      ,LastUpdateDate = GETDATE()  --<LastUpdateDate, datetime,>
                                                      ,CreatedBy = N'{33}'  --<CreatedBy, varchar(45),>
                                                      ,UpdatedBy = N'{33}'  --<UpdatedBy, varchar(45),>
                                                      ,TotalLength = {35}  --<TotalLength, decimal(20,9),>
                                                      ,CompletedRow = {36}  --<CompletedRow, int,>
                                                      ,QtyPerMaterial = {37}  --<QtyPerMaterial, int,>
                                                      ,Direction = '{38}'  --<Direction, nchar(10)>
                                                 WHERE LineID = {34}
                                            END" + Environment.NewLine
                                  , _session.CompanyID
                                  , _session.PlantID
                                  , head.WorkOrderID
                                  , 0 //Defualt TransactionLineID => Material Line
                                  , data.CutSeq.GetString()
                                  , data.SONo.GetString()           //{5}
                                  , data.SOLine.GetInt()
                                  , data.NORNum.GetString()
                                  , data.CommodityCode.GetString()
                                  , data.SpecCode.GetString()
                                  , data.CoatingCode.GetString()    //{10}
                                  , data.Thick
                                  , data.Width
                                  , data.Length
                                  , data.Status.GetString()
                                  , data.Stand      //{15}
                                  , data.CutDivision
                                  , data.UnitWeight
                                  , data.TotalWeight
                                  , data.CustID.GetString()
                                  , data.EndUserCode.GetString()    //{20}
                                  , data.DestinationCode.GetString()
                                  , data.QtyPack
                                  , data.Pack
                                  , data.SOWeight
                                  , data.SOQuantity     //{25}
                                  , data.CalQuantity
                                  , data.DeliveryDate.ToString("dd/MM/yyyy hh:mm:ss")
                                  , data.BussinessType.GetString()
                                  , data.Possession
                                  , data.ProductStatus.GetInt()      //{30}
                                  , data.Description.GetString()
                                  , data.Note.GetString()
                                  , _session.UserID
                                  , data.LineID.GetInt()
                                  , data.TotalLength.GetDecimal()
                                  , Convert.ToInt32(data.CompleteRow.GetInt())
                                  , data.QtyPerMaterial.GetDecimal()
                                  , string.IsNullOrEmpty(data.Direction.GetString()) ? "W" : data.Direction.GetString()
                                  );
            Repository.Instance.ExecuteWithTransaction(sql, "Update Cutting");

            return GetCuttingLines(head.WorkOrderID);
        }