protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString.Count > 0)
            {
                Int32.TryParse(Request.QueryString["id"], out branch_id1);
                //todo check if news_id is not valid

                if (Request.QueryString.Count == 3)
                {
                    edit_mode = true;
                }
            }

            if (!IsPostBack)
            {
                comboBroker.DataSource     = database.LoadBrokers(-1);
                comboBroker.DataTextField  = "name";
                comboBroker.DataValueField = "id";
                comboBroker.DataBind();


                ComboCity.DataSource     = database.LoadCities(-1);
                ComboCity.DataTextField  = "name";
                ComboCity.DataValueField = "id";
                ComboCity.DataBind();

                lblMesssage.Text = "";
                if (edit_mode)
                {
                    LoadBranch(database.LoadBranches(branch_id1));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Name:BtnSubmit_Click
        /// Description:Make Validation and then Insert into Table
        /// Author Name:Monal Shah
        /// Created Date:2010/12/6
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSubmit_Click(object sender, EventArgs e)
        {
            SqlConnection con     = new SqlConnection(CommonLogic.GetConnectionString);
            SqlCommand    ObjCmd  = new SqlCommand();
            Match         rexName = Regex.Match(TxtName.Text, "^[a-zA-Z\\ ]+$");
            Match         rexMail = Regex.Match(txtEmail.Text.Trim(' '), "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,4})$", RegexOptions.IgnoreCase);
            Match         rexFax  = Regex.Match(txtFax.Text.Trim(' '), "^[01]?[- .]?(\\([2-9]\\d{2}\\)|[2-9]\\d{2})[- .]?\\d{3}[- .]?\\d{4}$");

            try
            {
                if (TxtName.Text == string.Empty || TxtName.Text == null)
                {
                    MessageBox.Show("Please enter Name", "Enter Name"); TxtName.Focus();
                }
                else if (rexName.Success == false)
                {
                    MessageBox.Show("Please Enter Valid Name", "Enter Valid Name"); TxtName.Focus();
                }
                else if (txtEmail.Text == string.Empty)
                {
                    MessageBox.Show("Please Enter Email Address", "Enter Email Id"); txtEmail.Focus();
                }
                else if (rexMail.Success == false)
                {
                    MessageBox.Show("Please Enter Valid Email Address", "Enter Valid Email Id"); txtEmail.Focus();
                }
                else if (txtPwd.Text == string.Empty || txtPwd.Text == null)
                {
                    MessageBox.Show("Please Enter Password", "Enter Password"); txtPwd.Focus();
                }
                else if (DatePickerValue.Value > System.DateTime.Now)
                {
                    MessageBox.Show("Please Enter Less Than Current Date Value", "Enter Date"); DatePickerValue.Focus();
                }
                else if (txtFax.Text == string.Empty)
                {
                    MessageBox.Show("Please Enter Fax no.", "Enter Fax"); txtFax.Focus();
                }
                else if (rexFax.Success == false)
                {
                    MessageBox.Show("Please Enter Valid Fax no.", "Enter Valid Fax"); txtFax.Focus();
                }
                else if (ComboCountry.SelectedIndex == 0)
                {
                    MessageBox.Show("Please Select Country", "Select Country"); ComboCountry.Focus();
                }
                else if (comboState.Enabled == true)
                {
                    if (comboState.SelectedIndex == 0)
                    {
                        MessageBox.Show("Please Select State", "Select State"); comboState.Focus();
                    }
                    else if (ComboCity.Enabled == true)
                    {
                        if (ComboCity.SelectedIndex == 0)
                        {
                            MessageBox.Show("Please Select City", "Select City"); ComboCity.Focus();
                        }
                    }
                }
                if (ComboCity.SelectedIndex > 0)
                {
                    objDt = new DataTable();
                    ObjSb = new StringBuilder();
                    ObjSb.Append("Insert ");
                    ObjSb.Append("Into ");
                    ObjSb.Append("DetailsOfEmployee ");
                    ObjSb.Append("(Name,Sex,Email,DOB,PasswordValue,FaxNo,Country_Id,State_Id,City_Id,Salary)");
                    ObjSb.Append("Values ");
                    ObjSb.Append("(");
                    ObjSb.Append("'");
                    ObjSb.Append(TxtName.Text);
                    ObjSb.Append("'");
                    ObjSb.Append(",");
                    ObjSb.Append("'");
                    if (RbtnMale.Checked)
                    {
                        ObjSb.Append(RbtnMale.Text.ToString());
                    }
                    if (RbtnFemale.Checked)
                    {
                        ObjSb.Append(RbtnFemale.Text.ToString());
                    }
                    ObjSb.Append("'");
                    ObjSb.Append(",");
                    ObjSb.Append("'");
                    ObjSb.Append(txtEmail.Text);
                    ObjSb.Append("'");
                    ObjSb.Append(",");
                    ObjSb.Append("'");
                    ObjSb.Append(DatePickerValue.Text);
                    ObjSb.Append("'");
                    ObjSb.Append(",");
                    ObjSb.Append("'");
                    ObjSb.Append(txtPwd.Text);
                    ObjSb.Append("'");
                    ObjSb.Append(",");
                    ObjSb.Append("'");
                    ObjSb.Append(txtFax.Text);
                    ObjSb.Append("'");
                    ObjSb.Append(",");
                    ObjSb.Append("'");
                    ObjSb.Append(CountryId);
                    ObjSb.Append("'");
                    ObjSb.Append(",");
                    ObjSb.Append("'");
                    if (comboState.Enabled == true)
                    {
                        ObjSb.Append(StateId);
                    }
                    ObjSb.Append("'");
                    ObjSb.Append(",");
                    ObjSb.Append("'");
                    if (ComboCity.Enabled == true)
                    {
                        ObjSb.Append(CityId);
                    }
                    ObjSb.Append("'");
                    ObjSb.Append(",");
                    ObjSb.Append("'");
                    ObjSb.Append(Convert.ToInt32(ComboSalary.SelectedValue));
                    ObjSb.Append("'");
                    ObjSb.Append(")");
                    ObjCmd.CommandType = CommandType.Text;
                    ObjCmd.Connection  = con;
                    ObjCmd.CommandText = ObjSb.ToString();
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    ObjCmd.ExecuteNonQuery();
                    LblMsg.Visible = true;
                    LblMsg.Text    = ConstantMessage.InsertSuccessFully;
                    ClearControls();
                }
            }
            finally
            { ObjCmd.Dispose(); con.Close(); ObjSb = null; }
        }