コード例 #1
0
 private int GetPalletID(string palletNumber)
 {
     Pallet plt = new Pallet();
     plt.LoadByPalletNumber(palletNumber);
     if (plt.RowCount == 0)
     {
         plt.AddNew();
         plt.PalletNo = Convert.ToInt32(palletNumber);
         plt.Save();
     }
     return plt.ID;
 }
コード例 #2
0
        private bool PalletizationIsValid()
        {
            if (_dtPalletizedItemList == null)
            {
                return false;
            }
            bool valid = true;
            // check if the items are of equal quantity
            DataTable palletized = _dtPalletizedItemList.DefaultView.ToTable(); //(true, "Ordering", "Expiry Date");

            foreach (DataRow dr in palletized.Rows)
            {
                string guid = dr["GUID"].ToString();
                DataRow[] arrReceive = null;
                arrReceive = _dtRecGrid.Select(string.Format("[GUID] = '{0}'", guid));
                DataRow[] arrPalletized = null;
                arrPalletized = _dtPalletizedItemList.Select(string.Format("[GUID] = '{0}'", guid));
                DataRow[] arrNonPalletized = null;
                arrNonPalletized = _dtNonPalletizedItemList.Select(string.Format("[GUID] = '{0}'", guid));
                DataView dataView = null;
                if (grdShortageOrDamaged.DataSource != null)
                {
                    dataView = ((DataTable)grdShortageOrDamaged.DataSource).AsDataView();
                    dataView.RowFilter = string.Format("[GUID]='{0}' and [ShortageReasonID] = {1}", guid,
                        BLL.ShortageReasons.Constants.DAMAGED);
                    //Since we want to do quantity verification only, we need the damaged ones only.  This is because unlike the other type of discrepancies, the damaged adds quantity to the stock.
                }
                DataRowCollection arrDamaged = null;
                if (dataView != null)
                    arrDamaged = dataView.ToTable().Rows;

                // find sum of BU Qty in arr,
                decimal receiveQty = 0;
                decimal palletizedQty = 0;
                decimal nonPalletizedQty = 0;
                decimal damagedQty = 0;

                if (arrReceive != null)
                {
                    foreach (DataRow d in arrReceive)
                    {
                        d.ClearErrors();
                        receiveQty += Convert.ToDecimal(d["Pack Qty"]);
                    }
                }
                if (arrPalletized != null)
                {
                    foreach (DataRow d in arrPalletized)
                    {
                        d.ClearErrors();
                        palletizedQty += Convert.ToDecimal(d["Pack Qty"]);
                    }
                }

                if (arrNonPalletized != null)
                {
                    foreach (DataRow d in arrNonPalletized)
                    {
                        d.ClearErrors();
                        nonPalletizedQty += Convert.ToDecimal(d["Pack Qty"]);
                    }
                }

                if (arrDamaged != null)
                {
                    foreach (DataRow d in arrDamaged)
                    {
                        d.ClearErrors();
                        damagedQty += Convert.ToDecimal(d["Pack Qty"]);
                    }
                }

                if (receiveQty != (palletizedQty + nonPalletizedQty - damagedQty))
                {
                    foreach (DataRow d in arrPalletized)
                    {
                        d.SetColumnError("Pack Qty",
                            String.Format("Sum should be equal to what's specified in Step two({0})", receiveQty));
                    }
                    // this was an error
                    valid = false;

                }
            }

            Pallet plt = new Pallet();
            // check if the pallet # don't allow null or 0
            foreach (DataRow dr in _dtPalletizedItemList.Rows)
            {

                if (dr["PalletNumber"] == DBNull.Value || dr["PalletNumber"].ToString().Equals("") ||
                    Convert.ToInt32(dr["PalletNumber"]) == 0)
                {
                    dr.SetColumnError("PalletNumber", "The Pallet Number you specified is Already Used.");
                    valid = false;
                    continue;
                }
            }

            // check if same expiry on a single pallet location rule is held
            DataTable PalletNumbers = _dtPalletizedItemList.DefaultView.ToTable(true, "PalletNumber");
            foreach (DataRow dr in PalletNumbers.Rows)
            {
                // validate if the pallet number specified is not already used

                plt.LoadByPalletNumber(dr["PalletNumber"].ToString());

                if (plt.RowCount > 0)
                {
                    // there is an existing pallet number in the pallet list

                    DataRow[] darr =
                        _dtPalletizedItemList.Select(string.Format("PalletNumber = '{0}'", dr["PalletNumber"]));
                    foreach (DataRow d in darr)
                    {

                        if (!Convert.ToBoolean(d["Consolidate"]))
                        {
                            d.SetColumnError("PalletNumber", "The Pallet Number you specified is Already Used.");
                            valid = false;
                        }
                    }

                    continue;
                }

                DataRow[] arr1 = _dtPalletizedItemList.Select(string.Format("PalletNumber = '{0}'", dr["PalletNumber"]));
                int ItemID = 0;
                DateTime ExpiryDate = DateTime.Today;
                foreach (DataRow drw in arr1)
                {
                    if (ItemID == 0)
                    {
                        ItemID = Convert.ToInt32(drw["ID"]);
                        if (drw["Expiry Date"] != DBNull.Value)
                        {
                            ExpiryDate = Convert.ToDateTime(drw["Expiry Date"]);
                        }
                    }
                    else
                    {
                        //Validate if the same Item,with same Epiry date is in the same pallet
                        if (ItemID != Convert.ToInt32(drw["ID"]))
                        {
                            drw.SetColumnError("Item Name", "Different Items couldn't be put on the same pallet.");
                            valid = false;
                        }
                        if (drw["Expiry Date"] != DBNull.Value)
                        {
                            if (ExpiryDate.Subtract(Convert.ToDateTime(drw["Expiry Date"])).Days != 0)
                            {
                                drw.SetColumnError("Expiry Date",
                                    "Items With Different Expiry Date couldn't be put on the same pallet.");
                                valid = false;
                            }
                        }
                    }
                }
            }

            return valid;
        }