Exemplo n.º 1
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            Pioneertech.Consultancy.model.EmployeeDetail employeeDetail = new Pioneertech.Consultancy.model.EmployeeDetail
            {
                FirstName            = FirstNameTextBox.Text,
                LastName             = LastNameTextBox.Text,
                EmailId              = EmailIdTextBox.Text,
                PhoneNumber          = Convert.ToInt64(PhoneNumberTextBox.Text),
                AlternatePhoneNumber = Convert.ToInt64(AlternatePhoneNumberTextBox.Text),
                Address1             = Address1TextBox.Text,
                Address2             = Address2TextBox.Text,
                HomeCountry          = HomeCountryTextBox.Text,
                CurrentCountry       = CurrentCountryTextBox.Text,
                ZipCode              = Convert.ToInt32(ZipCodeTextBox.Text)
            };


            EmployeeDataAccessLayer employeeDAL = new EmployeeDataAccessLayer();
            int numberOfRowEffected             = employeeDAL.SaveEmployeeData(employeeDetail);

            if (numberOfRowEffected > 0)
            {
                string display = "Employee Data is Successfully Saved";
                ClientScript.RegisterStartupScript(this.GetType(), "Operation was", "alert('" + display + "');", true);
            }
            else
            {
                string display = "Employee Data not Saved. Please try again.";
                ClientScript.RegisterStartupScript(this.GetType(), "Operation was", "alert('" + display + "');", true);
            }
        }
Exemplo n.º 2
0
        protected void EditButton_Click(object sender, EventArgs e)
        {
            Pioneertech.Consultancy.model.EmployeeDetail employeeDetail = new Pioneertech.Consultancy.model.EmployeeDetail
            {
                FirstName            = FirstNameTextBox.Text,
                LastName             = LastNameTextBox.Text,
                EmailId              = EmailIdTextBox.Text,
                PhoneNumber          = Convert.ToInt64(PhoneNumberTextBox.Text),
                AlternatePhoneNumber = Convert.ToInt64(AlternatePhoneNumberTextBox.Text),
                Address1             = Address1TextBox.Text,
                Address2             = Address2TextBox.Text,
                HomeCountry          = HomeCountryTextBox.Text,
                CurrentCountry       = CurrentCountryTextBox.Text,
                ZipCode              = Convert.ToInt32(ZipCodeTextBox.Text)
            };
            int EmployeeId = int.Parse(EmployeeIdDropDownList.Text);


            SqlConnection mssqlconnection = new SqlConnection("Data Source=DESKTOP-I3T5H70;" +
                                                              "Initial Catalog=PioneerTech;" +
                                                              "Integrated Security=true");

            mssqlconnection.Open();
            string sql = $"UPDATE [EmployeeDetail] SET[FirstName] =  '{employeeDetail.FirstName}'," +
                         $"[LastName] = '{employeeDetail.LastName}'," +
                         $"[Email] = '{employeeDetail.EmailId}'," +
                         $"[ContactNumber] = {employeeDetail.PhoneNumber}," +
                         $"[AlternateContactNumber] = {employeeDetail.AlternatePhoneNumber}," +
                         $"[Address] =' {employeeDetail.Address1}'," +
                         $"[AlternateAddress] =' {employeeDetail.Address2}'," +
                         $"[HomeCountry] =' {employeeDetail.HomeCountry}'," +
                         $"[CurrentCountry] =' {employeeDetail.CurrentCountry}'," +
                         $"[ZipCode] = {employeeDetail.ZipCode} " +
                         $"WHERE EmployeeID= {EmployeeId}";
            SqlCommand command             = new SqlCommand(sql, mssqlconnection);
            int        numberOfRowEffected = command.ExecuteNonQuery();

            mssqlconnection.Close();

            if (numberOfRowEffected > 0)
            {
                string display = "Employee Company Data is Successfully Edited";
                ClientScript.RegisterStartupScript(this.GetType(), "Operation was", "alert('" + display + "');", true);
            }
            else
            {
                string display = "Employee Company Data not Edited. Please try again.";
                ClientScript.RegisterStartupScript(this.GetType(), "Operation was", "alert('" + display + "');", true);
            }
        }