Exemplo n.º 1
0
        /// <summary>
        /// To save details to database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        protected void SaveButton_Click(object sender, EventArgs e)
        {
            //int count = 0;
            string AlertMessage = string.Empty;
            string message      = string.Empty;

            if (MainOccupationTextBox.Text.ToString().Trim() == string.Empty)
            {
                //errMsgMainOccupationLabel.Text = "Enter the Concern";
            }
            else if (MainOccupationIDTextBox.Text.ToString().Trim() == string.Empty)
            {
                OccupationBLL OccupationBLLOBJ = new OccupationBLL();
                try
                {
                    string       uID           = Session["USER_ID"].ToString();
                    OccupationBO objOccupation = new OccupationBO();
                    objOccupation.OCCUPATIONNAME = MainOccupationTextBox.Text.ToString().Trim();
                    objOccupation.UserID         = Convert.ToInt32(uID);

                    OccupationBLL OccupationBLLobj = new OccupationBLL();
                    message = OccupationBLLobj.Insert(objOccupation);

                    //if (count == -1)
                    //{
                    //    msgSaveLabel.Text = "Data saved successfully"; //messageSaveLable
                    //    BindGrid(true, true);
                    //}
                    //else
                    //{
                    //    msgSaveLabel.Text = "Data not saved successfully";
                    //}

                    if (string.IsNullOrEmpty(message) || message == "" || message == "null")
                    {
                        message = "Data saved successfully";
                        AllClear();
                        // ClearDetails();
                        BindGrid(true, true);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                finally
                {
                    OccupationBLLOBJ = null;
                }
            }
            //edit the data in the textbox exiting in the Grid
            else if (MainOccupationIDTextBox.Text.ToString().Trim() != string.Empty)
            {
                ConcernBLL concernBLLOBJ = new ConcernBLL();

                try
                {
                    string       uID           = Session["USER_ID"].ToString();
                    OccupationBO objOccupation = new OccupationBO();
                    objOccupation.OCCUPATIONNAME = MainOccupationTextBox.Text.ToString().Trim();
                    objOccupation.OCCUPATIONID   = Convert.ToInt32(MainOccupationIDTextBox.Text.ToString().Trim());
                    objOccupation.UserID         = Convert.ToInt32(uID);

                    OccupationBLL OccupationBLLobj = new OccupationBLL();
                    message = OccupationBLLobj.EDITOccupation(objOccupation);

                    //if (count == -1)
                    //{
                    //    msgSaveLabel.Text = "Data saved successfully"; //messageSaveLable
                    //    BindGrid(true, true);
                    //}
                    //else
                    //{
                    //    msgSaveLabel.Text = "Data not saved successfully";
                    //}

                    if (string.IsNullOrEmpty(message) || message == "" || message == "null")
                    {
                        message = "Data updated successfully";
                        // ClearDetails();
                        AllClear();
                        BindGrid(true, true);
                        SetUpdateMode(false);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                finally
                {
                    concernBLLOBJ = null;
                }
            }
            AlertMessage = "alert('" + message + "');";
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true);
        }