Exemplo n.º 1
0
        private void btnadd_Click(object sender, EventArgs e)
        {
            age_find();

            FinindID();


            int insertrec = 0;

            try
            {
                if (txtempid.Text == "")
                {
                    MessageBox.Show("Employee ID Cannot Be Blank", "Insert", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    persond.EMPID       = txtempid.Text;
                    persond.DEPID       = cmb1.SelectedValue.ToString();
                    persond.FIRSTNAME   = txtfname.Text;
                    persond.LASTNAME    = txtlname.Text;
                    persond.FULLNAME    = txtfullname.Text;
                    persond.SEX         = cbgender.Text;
                    persond.CONFIRM     = cmbconf.Text;
                    persond.AGE         = int.Parse(age.ToString());
                    persond.DOB         = DateTime.Parse(dateTimePicker1.Text);
                    persond.NIC         = txtnic.Text;
                    persond.MSTATUS     = cmbsta.Text;
                    persond.ADDRESS     = txtaddress.Text;
                    persond.CITY        = txtcity.Text;
                    persond.COUNTRY     = txtcountry.Text;
                    persond.BUSNUMBER   = txtbisnum.Text;
                    persond.HOMENUMBER  = txthomenum.Text;
                    persond.BASIC       = txtnote.Text;
                    persond.DESIGNATION = txtdesig.Text;


                    insertrec = pbal.Insert(persond);

                    GridView1.DataSource = pbal.Bind_Getdata();
                    if (insertrec > 0)
                    {
                        MessageBox.Show("Record Insert Successfull", "Insert", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Record Already Insert!!!");
                    }
                }
            }
            catch (Exception ee)
            {
                ee.ToString();
            }
            finally
            {
            }
        }
    /// <summary>
    /// Add records into database
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AddRecords(object sender, EventArgs e)
    {
        //Lets validate the page first
        if (!Page.IsValid)
            return;

        int intResult = 0;
        // Page is valid, lets go ahead and insert records
        // Instantiate BAL object
        PersonBAL pBAL = new PersonBAL();
        // Instantiate the object we have to deal with
        Person person = new Person();
        // set the properties of the object
        person.FirstName = txtFirstName.Text;
        person.LastName = txtLastName.Text;
        person.Age = Int32.Parse(txtAge.Text);

        try
        {
            intResult = pBAL.Insert(person);
            if (intResult > 0)
                lblMessage.Text = "New record inserted successfully.";
            else
                lblMessage.Text = "FirstName [<b>"+ txtFirstName.Text +"</b>] alredy exists, try another name";

        }
        catch (Exception ee)
        {
            lblMessage.Text = ee.Message.ToString();
        }
        finally
        {
            person = null;
            pBAL = null;
        }
    }