예제 #1
0
        public IEnumerable<CommodityModel> GetByFilter(CommodityModel model)
        {
            IEnumerable<CommodityModel> query = GetAll();

            if (model.CommodityCode != null) { query = query.Where(p => p.CommodityCode.Contains(model.CommodityCode.ToString())); }
            if (model.CommodityName != null) { query = query.Where(p => p.CommodityName.Contains(model.CommodityName.ToString())); }

            return query;
        }
예제 #2
0
        private void butSearch_Click(object sender, EventArgs e)
        {
            CommodityModel model = new CommodityModel();
            model.CommodityCode = txtSpecID.Text.ToString();

            var list = _repo.GetByFilter(model);
            dgvList.Rows.Clear();
            ListToGrid(list);
        }
예제 #3
0
        /// <summary>
        /// For ITAKU
        /// </summary>
        /// <param name="grid"> DataGridView Name</param>
        /// <returns></returns>
        private bool ValidateGridCell(ref DataGridView grid)
        {
            lblValidation.Text = "";
            bool error = false;

            //Mapping data header for Maker and Customer
            //1. Check Maker
            if (string.IsNullOrEmpty(HeadContent.MakerName))
            {
                var result = _repoMaker.GetByID(HeadContent.MakerCode);
                if (result == null)
                {
                    MappingLookupModel model = new MappingLookupModel();
                    model.TypeCode = "MAKER";
                    model.SupplierCode = HeadContent.SupplierCode;
                    model.SupCode = txtMakerCode.Text.Trim();
                    var lookupResult = _repoLookup.GetByID(model);
                    if (lookupResult != null)
                    {
                        HeadContent.MakerCode = lookupResult.UCCCode;
                        var makerrow = _repoMaker.GetByID(HeadContent.MakerCode);
                        HeadContent.MakerName = makerrow.MakerName;
                    }
                    else
                    {
                        errorProvider1.SetError(txtMakerCode, "This Maker Code dosen't exist in the system.");
                        lblValidation.Text = "This Maker Code dosen't exist in the system.";
                        txtMakerCode.Focus();
                        return true;
                    }
                }
                else
                {
                    HeadContent.MakerCode = result.MakerCode;
                    HeadContent.MakerName = result.MakerName;
                }
            }

            //2. Check Customer
            if (string.IsNullOrEmpty(HeadContent.CustomerName))
            {
                var result = _repoCust.GetCustomerByID(HeadContent.CustID);
                if (result == null)
                {
                    MappingLookupModel model = new MappingLookupModel();
                    model.TypeCode = "CUST";
                    model.SupplierCode = HeadContent.SupplierCode;
                    model.SupCode = txtCustID.Text.Trim();
                    var lookupResult = _repoLookup.GetByID(model);
                    if (lookupResult != null)
                    {
                        HeadContent.CustID = lookupResult.UCCCode;
                        var custRow = _repoCust.GetCustomerByID(HeadContent.CustID);
                        HeadContent.CustomerName = custRow.CustName;
                    }
                    else
                    {
                        errorProvider1.SetError(txtCustID, "This Customer Code dosen't exist in the system.");
                        lblValidation.Text = "This Customer Code dosen't exist in the system.";
                        txtCustID.Focus();
                        return true;
                    }
                }
                else
                {
                    HeadContent.CustID = result.CustId;
                    HeadContent.CustomerName = result.CustName;
                }
            }
            //Set header content
            SetHeaderContent(HeadContent);

            for (int i = 0; (grid.Rows.Count) > i; i++)
            {
                if (string.IsNullOrEmpty(grid.Rows[i].Cells["id1"].Value.GetString())) return error;

                CommodityModel CommodityByRow = new CommodityModel();
                SpecModel SpecByRow = new SpecModel();
                CoatingModel CoatingByRow = new CoatingModel();
                WharehouseModel WhseByRow = new WharehouseModel();

                for (int j = 0; (grid.Columns.Count) > j; j++)
                {
                    try
                    {
                        //Article Duplicate
                        if (grid.Columns[j].Name == "article")
                        {
                            if (string.IsNullOrEmpty(grid[j, i].Value.GetString()))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Please fill data on current focus.";
                                return true;
                            }
                            else if (_repo.CheckArticleExisting(grid.Rows[i].Cells["article"].Value.GetString(), Convert.ToInt32(grid.Rows[i].Cells["id1"].Value.GetString().GetInt())))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "This Article number is duplicate.";
                                return true;
                            }
                            else
                            {
                                lblValidation.Text = "";
                            }
                        }

                        //Commodity	validation
                        if (grid.Columns[j].Name == "commodity1")
                        {
                            if (string.IsNullOrEmpty(grid[j, i].Value.GetString()))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Please fill data on current focus.";
                                return true;
                            }

                            CommodityByRow = _repoCmdt.GetByID(grid.Rows[i].Cells["commodity1"].Value.GetString());
                            if (CommodityByRow == null)
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "This Commodity Code dosen't exist in the system.";
                                return true;
                            }
                            else
                            {
                                lblValidation.Text = "";
                            }
                        }

                        //Specification depend on commodity
                        if (grid.Columns[j].Name == "spec1")
                        {
                            if (string.IsNullOrEmpty(grid[j, i].Value.GetString()))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Please fill data on current focus.";
                                return true;
                            }

                            SpecByRow = _repoSpec.GetByID(grid.Rows[i].Cells["spec1"].Value.GetString(), CommodityByRow.CommodityCode);
                            if (SpecByRow == null)
                            {
                                MappingLookupModel model = new MappingLookupModel();
                                model.TypeCode = "SPEC";
                                model.SupplierCode = HeadContent.SupplierCode;
                                model.SupCode = grid.Rows[i].Cells["spec1"].Value.GetString().Trim();
                                var result = _repoLookup.GetByID(model);
                                if (result != null)
                                {
                                    grid.Rows[i].Cells["spec1"].Value = result.UCCCode;
                                    grid.Rows[i].Cells["specname"].Value = _repoSpec.GetByID(result.UCCCode, result.UCCCodeForeign).SpecName;
                                    grid.Rows[i].Cells["commodity1"].Value = result.UCCCodeForeign;
                                    grid.Rows[i].Cells["cmdtname"].Value = _repoCmdt.GetByID(result.UCCCodeForeign).CommodityName;
                                }
                            }

                            SpecByRow = _repoSpec.GetByID(grid.Rows[i].Cells["spec1"].Value.GetString(), CommodityByRow.CommodityCode);
                            if (SpecByRow == null)
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "This Spec Code dosen't exist in the system or not relate with Commodity Code.";
                                return true;
                            }
                            else
                            {
                                lblValidation.Text = "";
                            }
                        }

                        //Commodity require coating
                        if (grid.Columns[j].Name == "Coating")
                        {
                            if (string.IsNullOrEmpty(grid[j, i].Value.GetString()) && CommodityByRow.CoatingRequire)
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Commodity [" + CommodityByRow.CommodityName + "] is require coating.";
                                return true;
                            }

                            if (!string.IsNullOrEmpty(grid[j, i].Value.GetString()))
                            {
                                CoatingByRow = _repoCoating.GetByID(grid.Rows[i].Cells["Coating"].Value.GetString());
                                if (CoatingByRow == null)
                                {
                                    grid.CurrentCell = grid[j, i];
                                    lblValidation.Text = "This Coating dosen't exist in the system.";
                                    return true;
                                }
                                else
                                {
                                    lblValidation.Text = "";
                                }
                            }
                        }

                        //Thick
                        if (grid.Columns[j].Name == "thick")
                        {
                            decimal tp;
                            if (!decimal.TryParse(Convert.ToString(grid.Rows[i].Cells["thick"].Value.GetString()), out tp))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Please enter numeric.";
                                return true;
                            }
                            else if (Convert.ToString(grid.Rows[i].Cells["thick"].Value.GetString()) == "0")
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Can't fill be zero.";
                                return true;
                            }
                            else
                            {
                                lblValidation.Text = "";
                            }
                        }

                        //Width
                        if (grid.Columns[j].Name == "width")
                        {
                            decimal tp;
                            if (!decimal.TryParse(Convert.ToString(grid.Rows[i].Cells["width"].Value.GetString()), out tp))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Please enter numeric.";
                                return true;
                            }
                            else if (Convert.ToString(grid.Rows[i].Cells["width"].Value.GetString()) == "0")
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Can't fill be zero.";
                                return true;
                            }
                            else
                            {
                                lblValidation.Text = "";
                            }
                        }

                        //Length
                        if (grid.Columns[j].Name == "length")
                        {
                            decimal tp;
                            if (!decimal.TryParse(Convert.ToString(grid.Rows[i].Cells["length"].Value.GetString()), out tp))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Please enter numeric.";
                                return true;
                            }
                            else
                            {
                                lblValidation.Text = "";
                            }
                        }

                        //Quantity
                        if (grid.Columns[j].Name == "quantity2")
                        {
                            decimal tp;
                            if (!decimal.TryParse(Convert.ToString(grid.Rows[i].Cells["quantity2"].Value.GetString()), out tp))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Please enter numeric.";
                                return true;
                            }
                            else if (Convert.ToString(grid.Rows[i].Cells["quantity2"].Value.GetString()) == "0")
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Can't fill be zero.";
                                return true;
                            }
                            else
                            {
                                lblValidation.Text = "";
                            }
                        }

                        //Weight
                        if (grid.Columns[j].Name == "weight2")
                        {
                            decimal tp;
                            if (!decimal.TryParse(Convert.ToString(grid.Rows[i].Cells["weight2"].Value.GetString()), out tp))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Please enter numeric.";
                                return true;
                            }
                            else if (Convert.ToString(grid.Rows[i].Cells["weight2"].Value.GetString()) == "0")
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Can't fill be zero.";
                                return true;
                            }
                            else
                            {
                                lblValidation.Text = "";
                            }
                        }

                        //Place dose existing
                        if (grid.Columns[j].Name == "place1")
                        {
                            if (string.IsNullOrEmpty(grid[j, i].Value.GetString()))
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "Please fill data on current focus.";
                                return true;
                            }

                            WhseByRow = _repoWhse.GetByID(grid.Rows[i].Cells["place1"].Value.GetString());
                            if (WhseByRow == null)
                            {
                                grid.CurrentCell = grid[j, i];
                                lblValidation.Text = "This Place dosen't exist in the system.";
                                return true;
                            }
                            else
                            {
                                lblValidation.Text = "";
                            }
                        }
                    }
                    catch (NullReferenceException ex)
                    {
                        return false;
                    }
                }
            }

            //if (Convert.ToDecimal(txtWeightBalnce.Text) != Convert.ToDecimal(txtRemainingWeight.Text))
            //{
            //    error = true;
            //    label5.Text = "Receipt weight must be equal Actual receipt weight!.";
            //}
            //else
            //{
            //    label5.Text = "";
            //}
            return error;
        }