protected void btnEdit_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                int    id  = -1;
                string _id = Request.QueryString["id"].ToString();
                int.TryParse(_id, out id);
                int userId = CurrentEnvironment.LoggedUser.Id;

                Manufacturer o = Manufacturer.GetManufacturerById(id);
                if (nameExists(txtName.Text.Replace("'", @"''")) && (o.Name != txtName.Text.Trim()))
                {
                    return;
                }
                if (codeExists(txtCode.Text.Replace("'", @"''")) && (o.Code != txtCode.Text.Trim()))
                {
                    return;
                }
                o.Name = txtName.Text.Replace("'", @"''");
                o.Code = txtCode.Text.Replace("'", @"''");
                o.Hl7ManufacturerId = int.Parse(ddlHl7Manufacturer.SelectedValue);
                o.IsActive          = bool.Parse(rblIsActive.SelectedValue);
                o.Notes             = txtNotes.Text.Replace("'", @"''");
                o.ModifiedOn        = DateTime.Now;
                o.ModifiedBy        = userId;

                int i = Manufacturer.Update(o);

                if (i > 0)
                {
                    lblSuccess.Visible       = true;
                    lblWarning.Visible       = false;
                    lblError.Visible         = false;
                    lblWarningRemove.Visible = false;
                    gridview_Databind(id);
                    ClearControls(this);
                }
                else
                {
                    lblSuccess.Visible       = false;
                    lblWarning.Visible       = false;
                    lblError.Visible         = true;
                    lblWarningRemove.Visible = false;
                }
            }
        }
        catch (Exception ex)
        {
            lblSuccess.Visible       = false;
            lblWarning.Visible       = false;
            lblError.Visible         = true;
            lblWarningRemove.Visible = false;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            List <string> actionList        = null;
            string        sessionNameAction = "";
            if (CurrentEnvironment.LoggedUser != null)
            {
                sessionNameAction = "__GIS_actionList_" + CurrentEnvironment.LoggedUser.Id;
                actionList        = (List <string>)Session[sessionNameAction];
            }

            if ((actionList != null) && actionList.Contains("ViewManufacturer") && (CurrentEnvironment.LoggedUser != null))
            {
                int    userId     = CurrentEnvironment.LoggedUser.Id;
                string language   = CurrentEnvironment.Language;
                int    languageId = int.Parse(language);
                Dictionary <string, string> wtList = (Dictionary <string, string>)HttpContext.Current.Cache["Manufacturer-dictionary" + language];
                if (wtList == null)
                {
                    List <WordTranslate> wordTranslateList = WordTranslate.GetWordByLanguage(languageId, "Manufacturer");
                    wtList = new Dictionary <string, string>();
                    foreach (WordTranslate vwt in wordTranslateList)
                    {
                        wtList.Add(vwt.Code, vwt.Name);
                    }
                    HttpContext.Current.Cache.Insert("Manufacturer-dictionary" + language, wtList);
                }

                //controls
                this.lblName.Text = wtList["ManufacturerName"];
                this.lblCode.Text = wtList["ManufacturerCode"];
                this.lblHl7ManufacturerId.Text = wtList["ManufacturerHl7Manufacturer"];
                this.lblIsActive.Text          = wtList["ManufacturerIsActive"];
                this.lblNotes.Text             = wtList["ManufacturerNotes"];

                //grid header text
                gvManufacturer.Columns[1].HeaderText = wtList["ManufacturerName"];
                gvManufacturer.Columns[2].HeaderText = wtList["ManufacturerCode"];
                //gvManufacturer.Columns[3].HeaderText = wtList["ManufacturerHl7Manufacturer"];
                gvManufacturer.Columns[4].HeaderText = wtList["ManufacturerIsActive"];
                gvManufacturer.Columns[3].HeaderText = wtList["ManufacturerNotes"];

                //actions
                this.btnAdd.Visible    = actionList.Contains("AddManufacturer");
                this.btnEdit.Visible   = actionList.Contains("EditManufacturer");
                this.btnRemove.Visible = actionList.Contains("RemoveManufacturer");

                //buttons
                this.btnAdd.Text    = wtList["ManufacturerAddButton"];
                this.btnEdit.Text   = wtList["ManufacturerEditButton"];
                this.btnRemove.Text = wtList["ManufacturerRemoveButton"];

                //message
                this.lblSuccess.Text = wtList["ManufacturerSuccessText"];
                this.lblWarning.Text = wtList["ManufacturerWarningText"];
                this.lblError.Text   = wtList["ManufacturerErrorText"];

                //Page Title
                this.lblTitle.Text = wtList["ManufacturerPageTitle"];

                //validators
                // rfvCode.ErrorMessage = wtList["ManufacturerMandatory"];
                rfvName.ErrorMessage = wtList["ManufacturerMandatory"];
                revCode.ErrorMessage = wtList["ManufacturerCodeValidator"];
                revName.ErrorMessage = wtList["ManufacturerNameValidator"];

                //Selected object
                int    id  = -1;
                string _id = Request.QueryString["id"];
                if (!String.IsNullOrEmpty(_id))
                {
                    int.TryParse(_id, out id);
                    Manufacturer o = Manufacturer.GetManufacturerById(id);
                    if (o.Hl7ManufacturerId != 0)
                    {
                        ddlHl7Manufacturer.SelectedValue = o.Hl7ManufacturerId.ToString();
                    }

                    txtName.Text  = o.Name;
                    txtCode.Text  = o.Code;
                    txtNotes.Text = o.Notes;
                    rblIsActive.Items[0].Selected = o.IsActive;
                    rblIsActive.Items[1].Selected = !o.IsActive;
                    gridview_Databind(id);
                    btnAdd.Visible = false;
                }
                else
                {
                    btnEdit.Visible   = false;
                    btnRemove.Visible = false;
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
    }
Exemple #3
0
        /// <summary>
        /// Initialize the test data
        /// </summary>
        public static void InitializeTestDataset()
        {
            /// Transaction type 999 = ID
            var transactionTypes = TransactionType.GetTransactionTypeList();

            if (!transactionTypes.Exists(o => o.Name == "Allocation"))
            {
                TransactionType.Insert(new TransactionType()
                {
                    Name = "Allocation"
                });
            }
            if (!transactionTypes.Exists(o => o.Name == "Transfer"))
            {
                TransactionType.Insert(new TransactionType()
                {
                    Name = "Transfer"
                });
            }


            // GTIN 12345 - PHARMACO OPV
            if (ItemManufacturer.GetItemManufacturerByGtin(GTIN_UNDER_TEST) == null)
            {
                // Item Category 999 = Vaccine
                if (ItemCategory.GetItemCategoryById(VACCINE_CATEGORY_ID) == null)
                {
                    VACCINE_CATEGORY_ID = ItemCategory.Insert(new ItemCategory()
                    {
                        Id         = VACCINE_CATEGORY_ID,
                        Code       = "VACCINE",
                        IsActive   = true,
                        ModifiedBy = 1,
                        ModifiedOn = DateTime.Now,
                        Name       = "Vaccine"
                    });
                }

                // Item 999 - OPV
                if (Item.GetItemById(OPV_ITEM_ID) == null)
                {
                    OPV_ITEM_ID = Item.Insert(new Item()
                    {
                        Code           = "OPV",
                        EntryDate      = DateTime.Now,
                        Id             = OPV_ITEM_ID,
                        ItemCategoryId = VACCINE_CATEGORY_ID,
                        IsActive       = true,
                        ModifiedBy     = 1,
                        ModifiedOn     = DateTime.Now,
                        Name           = "OPV"
                    });
                }

                // Unit of Measure
                if (Uom.GetUomById(DOSE_UOM_ID) == null)
                {
                    DOSE_UOM_ID = Uom.Insert(new Uom()
                    {
                        Id   = DOSE_UOM_ID,
                        Name = "DOSE"
                    });
                }

                // Manufacturer 999 - PHARMACO
                if (Manufacturer.GetManufacturerById(PHARMACO_MANUFACTURER_ID) == null)
                {
                    PHARMACO_MANUFACTURER_ID = Manufacturer.Insert(new Manufacturer()
                    {
                        Id         = PHARMACO_MANUFACTURER_ID,
                        Code       = "PHX",
                        IsActive   = true,
                        ModifiedBy = 1,
                        ModifiedOn = DateTime.Now,
                        Name       = "PHARMACO INC."
                    });
                }

                ItemManufacturer.Insert(new ItemManufacturer()
                {
                    Alt1QtyPer = 20,
                    BaseUom    = "DOSE",
                    BaseUomChildPerBaseUomParent = 10,
                    Gtin           = GTIN_UNDER_TEST,
                    IsActive       = true,
                    ItemId         = OPV_ITEM_ID,
                    ManufacturerId = PHARMACO_MANUFACTURER_ID,
                    ModifiedBy     = 1,
                    ModifiedOn     = DateTime.Now,
                    Price          = 9.99,
                    StorageSpace   = 1,
                    Alt1Uom        = "DOSE",
                    Alt2QtyPer     = 30,
                    Alt2Uom        = "DOSE"
                });
            }

            if (ItemLot.GetItemLotByGtin(GTIN_UNDER_TEST) == null)
            {
                // Item 999 - OPV
                if (Item.GetItemById(OPV_ITEM_ID) == null)
                {
                    OPV_ITEM_ID = Item.Insert(new Item()
                    {
                        Code           = "OPV",
                        EntryDate      = DateTime.Now,
                        Id             = OPV_ITEM_ID,
                        ItemCategoryId = VACCINE_CATEGORY_ID,
                        IsActive       = true,
                        ModifiedBy     = 1,
                        ModifiedOn     = DateTime.Now,
                        Name           = "OPV"
                    });
                }

                ItemLot.Insert(new ItemLot()
                {
                    ExpireDate = DateTime.Now.AddDays(10),
                    Gtin       = GTIN_UNDER_TEST,
                    ItemId     = OPV_ITEM_ID,
                    LotNumber  = GTIN_LOT_USE_FIRST
                });

                // Item Lot 2 - Will be more stock and expires later
                ItemLot.Insert(new ItemLot()
                {
                    ExpireDate = DateTime.Now.AddDays(40),
                    Gtin       = GTIN_UNDER_TEST,
                    ItemId     = OPV_ITEM_ID,
                    LotNumber  = GTIN_LOT_USE_LAST
                });

                // Item Lot 3 - Will trigger low stock
                ItemLot.Insert(new ItemLot()
                {
                    ExpireDate = DateTime.Now.AddDays(80),
                    Gtin       = GTIN_UNDER_TEST,
                    ItemId     = OPV_ITEM_ID,
                    LotNumber  = GTIN_LOT_LOW_BAL
                });
            }

            // Type 3 = DISTRICT
            if (HealthFacilityType.GetHealthFacilityTypeById(6) == null)
            {
                HealthFacilityType.Insert(new HealthFacilityType()
                {
                    Id         = 3,
                    Code       = "DISTRICT",
                    IsActive   = true,
                    ModifiedBy = 1,
                    ModifiedOn = DateTime.Now,
                    Name       = "DISTRICT LEVEL"
                });
            }

            // Type 6 = SDP
            if (HealthFacilityType.GetHealthFacilityTypeById(6) == null)
            {
                HealthFacilityType.Insert(new HealthFacilityType()
                {
                    Id         = 6,
                    Code       = "SDP",
                    IsActive   = true,
                    ModifiedBy = 1,
                    ModifiedOn = DateTime.Now,
                    Name       = "SDP"
                });
            }

            // HF888 = DISTRICT
            if (HealthFacility.GetHealthFacilityByCode("HF888") == null)
            {
                HealthFacility.Insert(new HealthFacility()
                {
                    Id   = 888,
                    Code = "HF888",
                    ColdStorageCapacity = 1000,
                    IsActive            = true,
                    Leaf             = false,
                    ParentId         = HealthFacility.GetHealthFacilityByParentId(0)[0].Id,
                    TopLevel         = false,
                    TypeId           = 3,
                    VaccinationPoint = false,
                    VaccineStore     = true,
                    ModifiedBy       = 1,
                    ModifiedOn       = DateTime.Now
                });
            }

            // GIVE HEALTH FACILITY SOME BALANCE
            var hf888Balances = HealthFacilityBalance.GetHealthFacilityBalanceByHealthFacilityCode("HF888");
            HealthFacilityBalance useFirst = hf888Balances.Find(o => o.Gtin == GTIN_UNDER_TEST && o.LotNumber == GTIN_LOT_USE_FIRST),
                                  useLast  = hf888Balances.Find(o => o.Gtin == GTIN_UNDER_TEST && o.LotNumber == GTIN_LOT_USE_LAST),
                                  lowStock = hf888Balances.Find(o => o.Gtin == GTIN_UNDER_TEST && o.LotNumber == GTIN_LOT_LOW_BAL);

            if (useFirst == null)
            {
                useFirst = new HealthFacilityBalance()
                {
                    Allocated          = 0,
                    Balance            = 500,
                    Distributed        = 0,
                    Gtin               = GTIN_UNDER_TEST,
                    HealthFacilityCode = "HF888",
                    LotNumber          = GTIN_LOT_USE_FIRST,
                    Received           = 0,
                    StockCount         = 500,
                    Used               = 0,
                    Wasted             = 0
                };
                hf888Balances.Add(useFirst);
                HealthFacilityBalance.Insert(useFirst);
            }
            else
            {
                useFirst.Balance    = 500;
                useFirst.StockCount = 500;
                HealthFacilityBalance.Update(useFirst);
            }

            if (useLast == null)
            {
                useLast = new HealthFacilityBalance()
                {
                    Allocated          = 0,
                    Balance            = 1000,
                    Distributed        = 0,
                    Gtin               = GTIN_UNDER_TEST,
                    HealthFacilityCode = "HF888",
                    LotNumber          = GTIN_LOT_USE_LAST,
                    Received           = 0,
                    StockCount         = 1000,
                    Used               = 0,
                    Wasted             = 0
                };
                hf888Balances.Add(useLast);
                HealthFacilityBalance.Insert(useLast);
            }
            else
            {
                useLast.Balance    = 1000;
                useLast.StockCount = 1000;
                HealthFacilityBalance.Update(useLast);
            }

            if (lowStock == null)
            {
                lowStock = new HealthFacilityBalance()
                {
                    Allocated          = 0,
                    Balance            = 10,
                    Distributed        = 0,
                    Gtin               = GTIN_UNDER_TEST,
                    HealthFacilityCode = "HF888",
                    LotNumber          = GTIN_LOT_LOW_BAL,
                    Received           = 0,
                    StockCount         = 10,
                    Used               = 0,
                    Wasted             = 0
                };
                hf888Balances.Add(lowStock);
                HealthFacilityBalance.Insert(lowStock);
            }
            else
            {
                useLast.Balance    = 10;
                useLast.StockCount = 10;
                HealthFacilityBalance.Update(lowStock);
            }

            // HF999 = SDP
            if (HealthFacility.GetHealthFacilityByCode("HF999") == null)
            {
                HealthFacility.Insert(new HealthFacility()
                {
                    Id   = 999,
                    Code = "HF999",
                    ColdStorageCapacity = 100,
                    IsActive            = true,
                    Leaf             = true,
                    ParentId         = HealthFacility.GetHealthFacilityByCode("HF888").Id,
                    TopLevel         = false,
                    TypeId           = 6,
                    VaccinationPoint = true,
                    VaccineStore     = true,
                    ModifiedOn       = DateTime.Now,
                    ModifiedBy       = 1
                });
            }
        }