Example #1
0
 protected void Save(object sender, EventArgs e)
 {
     try
     {
         if (txtFirstName.Text == "")
         {
             txtFirstName.Focus();
             ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Fill First Name')", true);
         }
         else if (btnSave.Text == "Save")
         {
             if (txtPwd.Text == "")
             {
                 txtPwd.Focus();
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Fill Password')", true);
             }
             else if (txtPhoneNo.Text == "")
             {
                 txtPhoneNo.Focus();
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Fill Phone No')", true);
             }
             con.Open();
             SqlTransaction trans = con.BeginTransaction(IsolationLevel.ReadCommitted);
             string         qry   = "";
             qry = "select max(User_Code) as User_Code from fbnpc_user_master";
             SqlCommand cmd = new SqlCommand(qry, con);
             cmd.Transaction = trans;
             cmd.Clone();
             SqlDataReader dr = cmd.ExecuteReader();
             while (dr.Read())
             {
                 objML_Logn.ID = dr["User_Code"].ToString();
             }
             if (clsCommon.myLen(objML_Logn.ID) <= 0)
             {
                 objML_Logn.ID = "USER00000001";
             }
             else
             {
                 objML_Logn.ID = clsCommon.incval(objML_Logn.ID);
             }
             con.Close();
             objML_Logn.UserName  = txtFirstName.Text != "" ? txtFirstName.Text : "";
             objML_Logn.LastName  = txtLastName.Text != "" ? txtLastName.Text : "";
             objML_Logn.Gender    = ddlGender.SelectedItem.Text != "" ? ddlGender.SelectedItem.Text : "";
             objML_Logn.DOB       = txtdate.Text != "" ? txtdate.Text : "";
             objML_Logn.Password  = objCommonClass.GetEncrptPassword(txtPwd.Text);
             objML_Logn.CPwd      = objCommonClass.GetEncrptPassword(txtCPwd.Text);
             objML_Logn.EmailID   = txtEmail.Text != "" ? txtEmail.Text : "";
             objML_Logn.PhoneNo   = txtPhoneNo.Text != "" ? txtPhoneNo.Text : "";
             objML_Logn.CreatedBy = Session["UserName"].ToString();
             objML_Logn.ModifyBy  = Session["UserName"].ToString();
             objML_Logn.IPAddress = GetIPAddress();
             //objML_Logn.ID = lblID.Text != "" ? lblID.Text : null;
             objML_Logn.ExamName = ddlExamList.SelectedItem.Value != "" ? ddlExamList.SelectedItem.Value : null;
             if (chkPratice.Checked == true)
             {
                 objML_Logn.Practice = "1";
             }
             else
             {
                 objML_Logn.Practice = "0";
             }
             if (chhkAdminGroup.Checked == true)
             {
                 objML_Logn.AdminGroup = "1";
             }
             else
             {
                 objML_Logn.AdminGroup = "0";
             }
             int x = objBL_Login.BL_InsUpdUserDetail(objML_Logn);
             if (x == 1)
             {
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('User Saved')", true);
                 BindProgramsInfo();
                 Reset();
             }
         }
         else
         {
             objML_Logn.UserName  = txtFirstName.Text != "" ? txtFirstName.Text : "";
             objML_Logn.LastName  = txtLastName.Text != "" ? txtLastName.Text : "";
             objML_Logn.Gender    = ddlGender.SelectedItem.Text != "" ? ddlGender.SelectedItem.Text : "";
             objML_Logn.DOB       = txtdate.Text != "" ? txtdate.Text : "";
             objML_Logn.Password  = objCommonClass.GetEncrptPassword(txtPwd.Text);
             objML_Logn.CPwd      = objCommonClass.GetEncrptPassword(txtCPwd.Text);
             objML_Logn.EmailID   = txtEmail.Text != "" ? txtEmail.Text : "";
             objML_Logn.PhoneNo   = txtPhoneNo.Text != "" ? txtPhoneNo.Text : "";
             objML_Logn.CreatedBy = Session["UserName"].ToString();
             objML_Logn.ModifyBy  = Session["UserName"].ToString();
             objML_Logn.IPAddress = GetIPAddress();
             objML_Logn.ID        = lblID.Text != "" ? lblID.Text : null;
             objML_Logn.ExamName  = ddlExamList.SelectedItem.Value != "" ? ddlExamList.SelectedItem.Value : null;
             if (chkPratice.Checked == true)
             {
                 objML_Logn.Practice = "1";
             }
             else
             {
                 objML_Logn.Practice = "0";
             }
             if (chhkAdminGroup.Checked == true)
             {
                 objML_Logn.AdminGroup = "1";
             }
             else
             {
                 objML_Logn.AdminGroup = "0";
             }
             int x = objBL_Login.BL_InsUpdUserDetail(objML_Logn);
             if (x == 1)
             {
                 ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('User Saved')", true);
                 BindProgramsInfo();
                 Reset();
             }
         }
     }
     catch (Exception ex)
     {
         ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('" + ex.Message.ToString() + "')", true);
     }
 }