Пример #1
0
        /// <summary>
        /// Saves the item policy
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            var itm    = new Items();
            var itmSup = new ItemSupplier();

            if (_itemId != 0)
            {
                itm.LoadByPrimaryKey(_itemId);
            }
            else
            {
                itm.AddNew();
                var prodCate = new ProductsCategory();
                prodCate.AddNew();
                prodCate.ItemId        = itm.ID;
                prodCate.SubCategoryID = Convert.ToInt32(_categoryId);
                prodCate.Save();
            }
            //if (rdA.Checked || rdB.Checked || rdC.Checked)
            //    itm.ABC = ((rdA.Checked) ? 1 : (rdB.Checked) ? 2 : 3);

            //if (rdV.Checked || rdE.Checked || rdN.Checked)
            //    itm.VEN = ((rdV.Checked) ? 1 : (rdE.Checked) ? 2 : 3);

            itm.IsInHospitalList = ckExculed.Checked;
            //itm.NeedExpiryBatch = chkNeedExpiryBatch.Checked;

            string valid = ValidateFields();

            if (valid == "true")
            {
                itm.NeedExpiryBatch = chkNeedExpiryBatch.Checked;
                itm.Pediatric       = chkIsVaccine.Checked; //wrong coulmn name but used to identify the vaccine items
                itm.StockCodeDACA   = txtText.Text;
                itm.Cost            = txtQuantityPerPack.Text;
                itm.Save();
            }

            else
            {
                XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }


            //TODO: To add categories
            //Needs some modification on edit


            // this will only add the suppliers
            //do some thing on edit

            itmSup.DeleteAllSupForItem(itm.ID);
            Supplier sup = new Supplier();

            foreach (object t in lstSuppliers.CheckedItems)
            {
                sup.GetSupplierByName(t.ToString());
                itmSup.AddNew();
                itmSup.ItemID     = itm.ID;
                itmSup.SupplierID = sup.ID;
                itmSup.Save();
            }

            var progItm = new ProgramProduct();

            progItm.DeleteAllProgramsForItem(_itemId);

            var prog = new Programs();

            //prog.AddNew();
            //prog.Name = cboPrograms.Text;
            //prog.Save();

            //foreach (object t in lstPrograms.CheckedItems)
            //{
            //    prog.GetProgramByName(t.ToString());
            //    progItm.AddNew();
            //    progItm.ItemID = itm.ID;
            //    progItm.ProgramID = prog.ID;
            //    progItm.StoreID = (progItm.ProgramID == 1000) ? 8 : 9;
            //    progItm.Save();
            //}
            if (rdSubProgram.EditValue != null)
            {
                progItm.AddNew();
                progItm.ItemID    = itm.ID;
                progItm.ProgramID = Convert.ToInt32(rdSubProgram.EditValue);
                progItm.StoreID   = 9;
                progItm.Save();
            }


            var duItem = new DUsItemList();
            var dus    = new ReceivingUnits();

            foreach (object t in lstDUs.CheckedItems)
            {
                dus.GetDUByName(t.ToString());
                duItem.AddNew();
                duItem.DUID   = dus.ID;
                duItem.ItemID = _itemId;
                try
                {
                    duItem.Save();
                }
                catch
                {
                }
            }

            XtraMessageBox.Show("Item Detail is Saved Successfully!", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
Пример #2
0
        public void InsertItems(List <ItemEntity> itemEntityList, string itemTradingTypeName, string objectTypeName)
        {
            using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
            {
                foreach (var itemEntity in itemEntityList)
                {
                    try
                    {
                        if (itemEntity.Code.Equals("EVE006"))
                        {
                            string debug = "Y";
                        }
                        //Check required
                        if (itemEntity.Code == null || itemEntity.Code.Trim().Length == 0)
                        {
                            continue;
                        }

                        //Check dupplicate code
                        bool isExist =
                            NAS.DAL.Util.isExistXpoObject <NAS.DAL.Nomenclature.Item.Item>
                                ("Code", itemEntity.Code,
                                Constant.ROWSTATUS_ACTIVE,
                                Constant.ROWSTATUS_DEFAULT,
                                Constant.ROWSTATUS_INACTIVE);
                        if (isExist)
                        {
                            continue;
                        }
                        //Get item trading type
                        ItemTradingType itemTradingType =
                            Util.getXPCollection <ItemTradingType>(uow, "Name", itemTradingTypeName).FirstOrDefault();
                        //Get Manufacturer
                        ManufacturerOrg manufacturerOrg =
                            Util.getXPCollection <ManufacturerOrg>(uow, "Code", itemEntity.ManufacturerCode,
                                                                   Constant.ROWSTATUS_ACTIVE).FirstOrDefault();

                        if (manufacturerOrg == null)
                        {
                            manufacturerOrg = Util.getDefaultXpoObject <ManufacturerOrg>(uow);
                        }

                        //Insert into Item table
                        NAS.DAL.Nomenclature.Item.Item item = new NAS.DAL.Nomenclature.Item.Item(uow)
                        {
                            Code                 = itemEntity.Code,
                            Description          = itemEntity.Description,
                            ManufacturerOrgId    = manufacturerOrg,
                            ItemTradingTypeId    = itemTradingType,
                            Name                 = itemEntity.Name,
                            RowStatus            = Constant.ROWSTATUS_ACTIVE,
                            RowCreationTimeStamp = DateTime.Now
                        };
                        item.Save();

                        //Get Supplier
                        SupplierOrg supplierOrg = Util.getXPCollection <SupplierOrg>(uow, "Code", itemEntity.SupplierCode,
                                                                                     Constant.ROWSTATUS_ACTIVE).FirstOrDefault();
                        if (supplierOrg != null)
                        {
                            //Insert into ItemSupplier table
                            ItemSupplier itemSupplier = new ItemSupplier(uow)
                            {
                                ItemId        = item,
                                SupplierOrgId = supplierOrg
                            };
                            itemSupplier.Save();
                        }

                        ObjectType objectType = Util.getXPCollection <ObjectType>(uow, "Name", objectTypeName,
                                                                                  Constant.ROWSTATUS_ACTIVE).FirstOrDefault();
                        if (objectType != null)
                        {
                            //Insert into ItemSupplier table
                            ItemCustomType itemCustomType = new ItemCustomType(uow)
                            {
                                ItemId       = item,
                                ObjectTypeId = objectType
                            };
                            itemCustomType.Save();
                        }

                        uow.CommitChanges();

                        //using (Session itemUnitSession = XpoHelper.GetNewSession())
                        //{
                        //    //Get UNIT relation type
                        //    ItemUnitRelationType unitRelationType =
                        //        NAS.DAL.Util.getXPCollection<ItemUnitRelationType>(itemUnitSession, "Name", "UNIT").FirstOrDefault();
                        //    itemEntity.ItemUnits = itemEntity.ItemUnits.OrderBy(r => r.Level).ToList();

                        //    ////Insert into ItemUnit
                        //    foreach (ItemUnitEntity itemUnitEntity in itemEntity.ItemUnits)
                        //    {

                        //        NAS.DAL.Nomenclature.Item.Item itemTemp =
                        //            NAS.DAL.Util.getXPCollection<NAS.DAL.Nomenclature.Item.Item>
                        //                (itemUnitSession, "Code", itemUnitEntity.ItemCode).FirstOrDefault();

                        //        Unit unit =
                        //            NAS.DAL.Util.getXPCollection<Unit>(itemUnitSession, "Code", itemUnitEntity.UnitCode).FirstOrDefault();

                        //        if (unit == null)
                        //            break;

                        //        Unit parentUnit =
                        //            NAS.DAL.Util.getXPCollection<Unit>(itemUnitSession, "Code", itemUnitEntity.ParentUnitCode).FirstOrDefault();

                        //        ItemUnit parentItemUnit = itemTemp.ItemUnits.Where(r => r.UnitId == parentUnit).FirstOrDefault();

                        //        ItemUnit itemUnit = new ItemUnit(itemUnitSession)
                        //        {
                        //            ItemId = itemTemp,
                        //            ItemUnitRelationTypeId = unitRelationType,
                        //            NumRequired = itemUnitEntity.NumRequired,
                        //            RowStatus = Constant.ROWSTATUS_ACTIVE,
                        //            UnitId = unit,
                        //            ParentItemUnitId = parentItemUnit,
                        //            RowCreationTimeStamp = DateTime.Now
                        //        };
                        //        itemUnit.Save();
                        //    }
                        //}
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                    }
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!AccountTypeSelectionValid())
            {
                XtraMessageBox.Show("Please choose to which account types this item applies to.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                gridViewStoreItemMatrix.SetColumnError(gridColAcctType, "At least one account type needs to be selected");
                return;
            }
            Item         itm    = new Item();
            ItemSupplier itmSup = new ItemSupplier();

            if (itemId != 0)
            {
                itm.LoadByPrimaryKey(itemId);
            }
            else
            {
                itm.AddNew();
                ItemCategory prodCate = new ItemCategory();
                prodCate.AddNew();
                prodCate.ItemId        = itm.ID;
                prodCate.SubCategoryID = Convert.ToInt32(categoryId);
                prodCate.Save();
            }
            if (radioGroupABC.EditValue != null)
            {
                itm.ABC = Convert.ToInt32(radioGroupABC.EditValue);
            }

            if (radioGroupVEN.EditValue != null)
            {
                itm.VEN = Convert.ToInt32(radioGroupVEN.EditValue);
            }
            itm.IsInHospitalList = ckExculed.Checked;
            itm.ProcessInDecimal = chkProcessDecimal.Checked;
            itm.Save();


            if (itm.IsInHospitalList)
            {
                SaveHubDetails();
            }
            else
            {
                // clear out the prefered locations
                // clear out the pick face locations
                // make sure that this item could be made not in the list
            }

            itmSup.DeleteAllSupForItem(itm.ID);
            Supplier sup = new Supplier();

            for (int i = 0; i < lstSuppliers.CheckedItems.Count; i++)
            {
                sup.GetSupplierByName(lstSuppliers.CheckedItems[i].ToString());
                itmSup.AddNew();
                itmSup.ItemID     = itm.ID;
                itmSup.SupplierID = sup.ID;
                itmSup.Save();
            }

            ItemProgram progItm = new ItemProgram();

            progItm.DeleteAllProgramsForItem(itemId);
            BLL.Program prog = new BLL.Program();
            for (int i = 0; i < lstPrograms.CheckedItems.Count; i++)
            {
                prog.GetProgramByName(lstPrograms.CheckedItems[i].ToString());
                progItm.AddNew();
                progItm.ItemID    = itm.ID;
                progItm.ProgramID = prog.ID;
                progItm.Save();
            }

            XtraMessageBox.Show("Item Detail is Saved Successfully!", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }