Ejemplo n.º 1
0
        protected void imgBtnInsert_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                if (Session["RespMaintData"] != null)
                {
                    DataTable dtResponsibilityData = Session["RespMaintData"] as DataTable;
                    if (dtResponsibilityData.Select("responsibility_code = '" + txtResponsibilityCode.Text + "'").Length != 0)
                    {
                        msgView.SetMessage("Cannot save - Responsibility already exists with this Code.", MessageType.Success, PositionType.Auto);
                        return;
                    }
                    else if (dtResponsibilityData.Select("responsibility_desc = '" + txtResponsibilityDesc.Text + "'").Length != 0)
                    {
                        msgView.SetMessage("Cannot save - Responsibility already exists with this Name.", MessageType.Success, PositionType.Auto);
                        return;
                    }
                }

                string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());

                responsibilityMaintenanceBL = new ResponsibilityMaintenanceBL();
                DataSet responsibilityData = responsibilityMaintenanceBL.InsertResponsibilityData(txtResponsibilityCode.Text.Trim(), txtResponsibilityDesc.Text.Trim(), ddlNewManagerResp.SelectedValue, userCode, out errorId);
                responsibilityMaintenanceBL = null;

                if (responsibilityData.Tables.Count != 0 && errorId != 2)
                {
                    Session["RespMaintData"]     = responsibilityData.Tables[0];
                    Session["RespMaintMngrResp"] = responsibilityData.Tables[1];
                    Session["FuzzySearchAllResponsibilityList"] = responsibilityData.Tables[2];

                    BindGrid(responsibilityData.Tables[0]);
                    PopulateDropdowns(responsibilityData.Tables[1]);
                    txtResponsibilityDesc.Text      = string.Empty;
                    txtResponsibilityCode.Text      = string.Empty;
                    txtResponsibilitySearch.Text    = string.Empty;
                    ddlNewManagerResp.SelectedIndex = 0;
                    hdnChangeNotSaved.Value         = "N";
                    hdnInsertDataNotSaved.Value     = "N";
                    hdnGridRowSelectedPrvious.Value = null;
                    msgView.SetMessage("Responsibility created successfully.", MessageType.Success, PositionType.Auto);
                }
                else
                {
                    msgView.SetMessage("Failed to create responsibility.", MessageType.Warning, PositionType.Auto);
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in creating responsibility.", ex.Message);
            }
        }
Ejemplo n.º 2
0
        protected void btnSaveChanges_Click(object sender, EventArgs e)
        {
            try
            {
                if (hdnInsertDataNotSaved.Value == "Y")
                {
                    //Validate
                    Page.Validate("valInsertResponsibility");
                    if (!Page.IsValid)
                    {
                        mpeSaveUndo.Hide();
                        msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto);
                        return;
                    }

                    if (Session["RespMaintData"] != null)
                    {
                        DataTable dtResponsibilityData = Session["RespMaintData"] as DataTable;
                        if (dtResponsibilityData.Select("responsibility_code = '" + txtResponsibilityCode.Text + "'").Length != 0)
                        {
                            msgView.SetMessage("Responsibility already exists with this responsibility code.", MessageType.Success, PositionType.Auto);
                            return;
                        }
                        else if (dtResponsibilityData.Select("responsibility_desc = '" + txtResponsibilityDesc.Text + "'").Length != 0)
                        {
                            msgView.SetMessage("Responsibility already exists with this responsibility desc.", MessageType.Success, PositionType.Auto);
                            return;
                        }
                    }


                    string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());

                    responsibilityMaintenanceBL = new ResponsibilityMaintenanceBL();
                    DataSet responsibilityData = responsibilityMaintenanceBL.InsertResponsibilityData(txtResponsibilityCode.Text.Trim(), txtResponsibilityDesc.Text.Trim(), ddlNewManagerResp.SelectedValue, userCode, out errorId);
                    responsibilityMaintenanceBL = null;

                    if (responsibilityData.Tables.Count != 0 && errorId != 2)
                    {
                        Session["RespMaintData"]     = responsibilityData.Tables[0];
                        Session["RespMaintMngrResp"] = responsibilityData.Tables[1];
                        Session["FuzzySearchAllResponsibilityList"] = responsibilityData.Tables[2];

                        BindGrid(responsibilityData.Tables[0]);
                        PopulateDropdowns(responsibilityData.Tables[1]);
                        txtResponsibilityDesc.Text      = string.Empty;
                        txtResponsibilityCode.Text      = string.Empty;
                        txtResponsibilitySearch.Text    = string.Empty;
                        ddlNewManagerResp.SelectedIndex = 0;
                        hdnChangeNotSaved.Value         = "N";
                        hdnInsertDataNotSaved.Value     = "N";
                        hdnGridRowSelectedPrvious.Value = null;
                        msgView.SetMessage("Responsibility created successfully.", MessageType.Success, PositionType.Auto);
                    }
                    else
                    {
                        msgView.SetMessage("Failed create responsibility.", MessageType.Warning, PositionType.Auto);
                    }
                }
                else if (hdnChangeNotSaved.Value == "Y")
                {
                    //Validate
                    Page.Validate("valUpdateResponsibility");
                    if (!Page.IsValid)
                    {
                        mpeSaveUndo.Hide();
                        msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto);
                        return;
                    }

                    string userCode              = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString());
                    int    rowIndex              = Convert.ToInt32(hdnGridRowSelectedPrvious.Value);
                    string responsibilityCode    = ((Label)gvResponsibilityDetails.Rows[rowIndex].FindControl("lblResponsibilityCode")).Text;
                    string responsibilityDesc    = ((TextBox)gvResponsibilityDetails.Rows[rowIndex].FindControl("txtResponsibilityName")).Text;
                    string managerResponsibility = ((DropDownList)gvResponsibilityDetails.Rows[rowIndex].FindControl("ddlGridManagerResp")).SelectedValue;

                    responsibilityMaintenanceBL = new ResponsibilityMaintenanceBL();
                    DataSet responsibilityData = responsibilityMaintenanceBL.UpdateResponsibilityData(responsibilityCode, responsibilityDesc, managerResponsibility, userCode, out errorId);
                    responsibilityMaintenanceBL = null;

                    if (responsibilityData.Tables.Count != 0 && errorId != 2)
                    {
                        Session["RespMaintData"]     = responsibilityData.Tables[0];
                        Session["RespMaintMngrResp"] = responsibilityData.Tables[1];
                        Session["FuzzySearchAllResponsibilityList"] = responsibilityData.Tables[2];

                        //check if there is only one row in the grid before binding updated data.
                        //if count is 1 then only display that row
                        if (gvResponsibilityDetails.Rows.Count == 1)
                        {
                            DataTable dtSearched = responsibilityData.Tables[0].Clone();
                            DataRow[] foundRows  = responsibilityData.Tables[0].Select("responsibility_code = '" + responsibilityCode + "'");
                            if (foundRows.Length != 0)
                            {
                                dtSearched = foundRows.CopyToDataTable();
                                BindGrid(dtSearched);
                            }
                        }
                        else
                        {
                            BindGrid(responsibilityData.Tables[0]);
                        }
                        PopulateDropdowns(responsibilityData.Tables[1]);
                        hdnChangeNotSaved.Value         = "N";
                        hdnGridRowSelectedPrvious.Value = null;
                        msgView.SetMessage("Responsibility details updated successfully.", MessageType.Success, PositionType.Auto);
                    }
                    else
                    {
                        msgView.SetMessage("Failed to updated responsibility details.", MessageType.Warning, PositionType.Auto);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("Error in saving grid data", ex.Message);
            }
        }