Exemplo n.º 1
0
        public ProductWeightViewModel(UserInformation userInfo, string ciReference, string weightOption, OperationMode mode, int entityPrimaryKey)
        {
            _productWeightBll      = new ProductWeightBll(userInfo);
            ProductWeight          = new ProductWeightModel();
            this._saveCommand      = new DelegateCommand(this.Save);
            this._calculateCommand = new DelegateCommand(this.Calculate);
            this._closeCommand     = new DelegateCommand(this.Close);
            //this._cellEditEndingCommand = new DelegateCommand<object>(this.CellEditEnding);
            this._rowEditEndingCommand         = new DelegateCommand <DataRowView>(this.RowEditEnding);
            this._deleteCommand                = new DelegateCommand <DataRowView>(this.DeleteShapeDetail);
            this._lostFocusCheeseWeightCommand = new DelegateCommand(this.CheeseWeight_LostFocus);
            this._onShapeSelectionChanged      = new DelegateCommand(this.ShapeCode_SelectionChanged);

            DropdownHeaders = new ObservableCollection <DropdownColumns>
            {
                new DropdownColumns {
                    ColumnName = "SHAPE_CODE", ColumnDesc = "Shape Code", ColumnWidth = 120
                },
                new DropdownColumns {
                    ColumnName = "SHAPE_NAME", ColumnDesc = "Shape", ColumnWidth = "1*"
                }
            };

            ProductWeight.CIREF_NO_FK  = entityPrimaryKey;
            ProductWeight.CIreference  = ciReference;
            ProductWeight.WeightOption = weightOption;
            operaionmode = mode;
            if (weightOption == "C")
            {
                WeightOptionText = "Cheese Weight : ";
            }
            else if (weightOption == "F")
            {
                WeightOptionText = "Finish Weight : ";
            }
            if (mode == OperationMode.Edit)
            {
                IsReadOnlyCheeseWeight = true;
                _productWeightBll.CopyProcess(ProductWeight);
            }


            _productWeightBll.GetShapeDetails(ProductWeight);

            if (ProductWeight.DVShapeDetails.Count > 0)
            {
                ProductWeightSelectedItem = ProductWeight.DVShapeDetails[0];
            }

            if (mode == OperationMode.Edit)
            {
                Calculate();
            }
        }
Exemplo n.º 2
0
        public decimal GenerateSNO(ProductWeightModel productwt)
        {
            try
            {
                decimal sno = (from o in DB.DDSHAPE_DETAILS where o.CI_REFERENCE == productwt.CIreference && o.WEIGHT_OPTION == productwt.WeightOption select o.SNO).Max();

                return(Convert.ToDecimal(sno) + 1);
            }
            catch (Exception ex)
            {
                ex.LogException();
                return(1);
            }
        }
Exemplo n.º 3
0
        public void CopyProcess(ProductWeightModel productweight)
        {
            try
            {
                string varCopy = (productweight.WeightOption == "C") ? "F" : "C";

                int cnt = (from o in DB.DDSHAPE_DETAILS
                           where o.CI_REFERENCE == productweight.CIreference && o.WEIGHT_OPTION == productweight.WeightOption
                           select o).Count();
                if (cnt == 0)
                {
                    List <DDSHAPE_DETAILS> sdetails = (from o in DB.DDSHAPE_DETAILS
                                                       where o.CI_REFERENCE == productweight.CIreference && o.WEIGHT_OPTION == varCopy
                                                       select o).ToList <DDSHAPE_DETAILS>();
                    if (sdetails != null)
                    {
                        foreach (DDSHAPE_DETAILS sdetail in sdetails)
                        {
                            DDSHAPE_DETAILS shapedetail = new DDSHAPE_DETAILS();
                            shapedetail.CI_REFERENCE  = productweight.CIreference;
                            shapedetail.WEIGHT_OPTION = productweight.WeightOption;
                            shapedetail.SHAPE_CODE    = sdetail.SHAPE_CODE;
                            shapedetail.SNO           = GenerateSNO(productweight);
                            shapedetail.HEAD1         = sdetail.HEAD1;
                            shapedetail.HEAD2         = sdetail.HEAD2;
                            shapedetail.HEAD3         = sdetail.HEAD3;
                            shapedetail.VAL1          = sdetail.VAL1;
                            shapedetail.VAL2          = sdetail.VAL2;
                            shapedetail.VAL3          = sdetail.VAL3;
                            shapedetail.VOLUME        = sdetail.VOLUME;
                            shapedetail.SIGN          = sdetail.SIGN;

                            shapedetail.ROWID = Guid.NewGuid();
                            DB.DDSHAPE_DETAILS.InsertOnSubmit(shapedetail);
                            DB.SubmitChanges();
                        }
                    }
                    sdetails = null;
                }
            }
            catch (System.Data.Linq.ChangeConflictException)
            {
                DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
        }
Exemplo n.º 4
0
        public bool GetShapeDetails(ProductWeightModel productweight)
        {
            try
            {
                DataTable dt = new DataTable();
                dt = ToDataTable((from o in DB.DDSHAPE_MAST
                                  select new { o.SHAPE_CODE, o.SHAPE_NAME, o.ROWID }).ToList());
                if (dt != null)
                {
                    productweight.DVShape = dt.DefaultView;
                }
                else
                {
                    productweight.DVShape = null;
                }

                dt = ToDataTable((from o in DB.DDSHAPE_DETAILS
                                  where o.CI_REFERENCE == productweight.CIreference && o.WEIGHT_OPTION == productweight.WeightOption
                                  select new { o.CI_REFERENCE, o.WEIGHT_OPTION, o.SNO, o.SHAPE_CODE, o.HEAD1, o.VAL1, o.HEAD2, o.VAL2, o.HEAD3, o.VAL3, o.VOLUME, o.SIGN, o.ROWID }).ToList());
                if (dt != null)
                {
                    productweight.DVShapeDetails = dt.DefaultView;
                    productweight.DVShapeDetails.AddNew();
                    productweight.DTDeletedRecords = dt.Clone();
                }
                else
                {
                    productweight.DVShapeDetails = null;
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
        }
Exemplo n.º 5
0
        public bool UpdateProductWeight(ProductWeightModel productwt)
        {
            bool _status = false;

            productwt.Status = "";

            try
            {
                foreach (DataRowView dr in productwt.DVShapeDetails)
                {
                    if (dr["SHAPE_CODE"].ToString() != "")
                    {
                        try
                        {
                            if (dr["ROWID"].ToString() != "")
                            {
                                DDSHAPE_DETAILS sdetails = (from o in DB.DDSHAPE_DETAILS
                                                            where o.ROWID.ToString() == dr["ROWID"].ToString()
                                                            select o).FirstOrDefault <DDSHAPE_DETAILS>();
                                if (sdetails != null)
                                {
                                    sdetails.CI_REFERENCE = productwt.CIreference;
                                    //sdetails.CIREF_NO_FK = productwt.CIREF_NO_FK;
                                    sdetails.WEIGHT_OPTION = productwt.WeightOption;
                                    sdetails.SHAPE_CODE    = dr["SHAPE_CODE"].ToString();
                                    sdetails.SNO           = dr["SNO"].ToString().ToDecimalValue();
                                    sdetails.HEAD1         = dr["HEAD1"].ToString();
                                    sdetails.HEAD2         = dr["HEAD2"].ToString();
                                    sdetails.HEAD3         = dr["HEAD3"].ToString();
                                    sdetails.VAL1          = dr["VAL1"].ToString().ToDecimalValue();
                                    sdetails.VAL2          = dr["VAL2"].ToString().ToDecimalValue();
                                    sdetails.VAL3          = dr["VAL3"].ToString().ToDecimalValue();
                                    sdetails.VOLUME        = dr["VOLUME"].ToString().ToDecimalValue();
                                    sdetails.SIGN          = dr["SIGN"].ToString();
                                    DB.SubmitChanges();
                                    sdetails         = null;
                                    productwt.Status = "Record Updated successfully.";
                                }
                            }
                            else
                            {
                                DDSHAPE_DETAILS sdetails = new DDSHAPE_DETAILS();
                                sdetails.CI_REFERENCE = productwt.CIreference;

                                //if (productwt.CIREF_NO_FK > 0)
                                //    sdetails.CIREF_NO_FK = productwt.CIREF_NO_FK;

                                sdetails.WEIGHT_OPTION = productwt.WeightOption;
                                sdetails.SHAPE_CODE    = dr["SHAPE_CODE"].ToString();
                                sdetails.SNO           = GenerateSNO(productwt);
                                sdetails.HEAD1         = dr["HEAD1"].ToString();
                                sdetails.HEAD2         = dr["HEAD2"].ToString();
                                sdetails.HEAD3         = dr["HEAD3"].ToString();
                                sdetails.VAL1          = dr["VAL1"].ToString().ToDecimalValue();
                                sdetails.VAL2          = dr["VAL2"].ToString().ToDecimalValue();
                                sdetails.VAL3          = dr["VAL3"].ToString().ToDecimalValue();
                                sdetails.VOLUME        = dr["VOLUME"].ToString().ToDecimalValue();
                                sdetails.SIGN          = dr["SIGN"].ToString();

                                sdetails.ROWID = Guid.NewGuid();
                                DB.DDSHAPE_DETAILS.InsertOnSubmit(sdetails);
                                DB.SubmitChanges();
                                sdetails         = null;
                                productwt.Status = "Record Updated successfully.";
                            }
                        }
                        catch (System.Data.Linq.ChangeConflictException)
                        {
                            DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
                            productwt.Status = "Record Added successfully.";
                        }
                        catch (Exception ex)
                        {
                            throw ex.LogException();
                        }
                    }
                }

                foreach (DataRow dr in productwt.DTDeletedRecords.Rows)
                {
                    try
                    {
                        if (dr["ROWID"].ToString().Trim() != "")
                        {
                            DDSHAPE_DETAILS sdetails = (from o in DB.DDSHAPE_DETAILS
                                                        where o.ROWID.ToString() == dr["ROWID"].ToString()
                                                        select o).FirstOrDefault <DDSHAPE_DETAILS>();

                            if (sdetails != null)
                            {
                                DB.DDSHAPE_DETAILS.DeleteOnSubmit(sdetails);
                                DB.SubmitChanges();
                            }
                            sdetails = null;
                            _status  = true;
                        }
                    }
                    catch (System.Data.Linq.ChangeConflictException)
                    {
                        DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
                        _status = true;
                    }
                    catch (Exception ex)
                    {
                        _status = false;
                        throw ex.LogException();
                    }
                }

                _status = true;
            }
            catch (System.Data.Linq.ChangeConflictException)
            {
                DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
            }
            catch (Exception ex)
            {
                DB.Transaction.Rollback();
                throw ex.LogException();
            }
            return(_status);
        }