Exemplo n.º 1
0
        protected void frmHealthAndSafety_ItemCommand(object sender, FormViewCommandEventArgs e)
        {
            DropDownList ddlHSCategory = (DropDownList)frmHealthAndSafety.FindControl("ddlHSCategory");
            DropDownList ddlHSName     = (DropDownList)frmHealthAndSafety.FindControl("ddlHSName");
            TextBox      txtHSValue    = (TextBox)frmHealthAndSafety.FindControl("txtHSValue");
            TextBox      txtRemarks    = (TextBox)frmHealthAndSafety.FindControl("txtRemarks");

            if (e.CommandName.ToString() == "Add")
            {
                TLGX_Consumer.MDMSVC.DC_Accommodation_HealthAndSafety newObj = new MDMSVC.DC_Accommodation_HealthAndSafety
                {
                    Accommodation_HealthAndSafety_Id = Guid.NewGuid(),
                    Accommodation_Id = Guid.Parse(Request.QueryString["Hotel_Id"]),
                    Create_Date      = DateTime.Now,
                    Create_User      = System.Web.HttpContext.Current.User.Identity.Name,
                    Edit_Date        = DateTime.Now, //using edit date to carry last updated date onto UI so we need to set it here, breaking design pattern

                    Description = txtHSValue.Text.Trim(),
                    Category    = ddlHSCategory.SelectedItem.Text.Trim(),
                    Name        = ddlHSName.SelectedItem.Text.Trim(),
                    Remarks     = txtRemarks.Text.Trim(),
                    IsActive    = true
                };
                if (AccSvc.AddHealthAndSafety(newObj))
                {
                    frmHealthAndSafety.ChangeMode(FormViewMode.Insert);
                    frmHealthAndSafety.DataBind();
                    GetHealthAndSafetyDetails();
                    BootstrapAlert.BootstrapAlertMessage(dvMsg, "H/S has been added successfully", BootstrapAlertType.Success);
                }
                else
                {
                    BootstrapAlert.BootstrapAlertMessage(dvMsg, "Error Occurred", BootstrapAlertType.Warning);
                }
            }


            if (e.CommandName.ToString() == "Modify")
            {
                Accomodation_ID = new Guid(Request.QueryString["Hotel_Id"]);
                Guid myRow_Id = Guid.Parse(grdHealthAndSafety.SelectedDataKey.Value.ToString());

                var result = AccSvc.GetHealthAndSafetyDetails(Accomodation_ID, myRow_Id);

                if (result.Count > 0)
                {
                    TLGX_Consumer.MDMSVC.DC_Accommodation_HealthAndSafety newObj = new MDMSVC.DC_Accommodation_HealthAndSafety
                    {
                        Accommodation_HealthAndSafety_Id = myRow_Id,
                        Accommodation_Id = Guid.Parse(Request.QueryString["Hotel_Id"]),
                        Edit_User        = System.Web.HttpContext.Current.User.Identity.Name,
                        Edit_Date        = DateTime.Now, // using edit date to carry last updated date onto UI so we need to set it here, breaking design pattern

                        Description = txtHSValue.Text.Trim(),
                        Category    = ddlHSCategory.SelectedItem.Text.Trim(),
                        Name        = ddlHSName.SelectedItem.Text.Trim(),
                        Remarks     = txtRemarks.Text.Trim(),
                        IsActive    = true
                    };

                    if (AccSvc.UpdateHealthAndSafety(newObj))
                    {
                        frmHealthAndSafety.ChangeMode(FormViewMode.Insert);
                        frmHealthAndSafety.DataBind();
                        GetHealthAndSafetyDetails();
                        BootstrapAlert.BootstrapAlertMessage(dvMsg, "H/S has been updated successfully", BootstrapAlertType.Success);
                    }
                    else
                    {
                        BootstrapAlert.BootstrapAlertMessage(dvMsg, "Error Occurred", BootstrapAlertType.Warning);
                    }
                }
            }
        }