private void btnNewCustomer_Click(object sender, RoutedEventArgs e) { emp.First_Name = fname; emp.Last_Name = lname; emp.Remarks = ""; emp.Address1 = txtAddress1.Text; emp.Address2 = txtAddress2.Text; emp.Mobile1 = txtMobile1.Text; emp.Mobile2 = txtMobile2.Text; emp.EmailId = txtEmail.Text; emp.Flag = 1; if (txtEmail.Text.Length == 0) { MessageBox.Show("Enter an email."); txtEmail.Focus(); } else if (txtFileName.Text == "") { MessageBox.Show("Enter an Image"); txtFileName.Focus(); } else if (!Regex.IsMatch(txtEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Enter a valid email."); txtEmail.Select(0, txtEmail.Text.Length); txtEmail.Focus(); } else { //Initialize a file stream to read the image file FileStream fs = new FileStream(txtFileName.Text, FileMode.Open, FileAccess.Read); byte[] imgByteArr = new byte[fs.Length]; string[] files = fs.Name.Split(new char[] { '\\' }); string fileName = files[files.Length - 1]; Stream stream = new MemoryStream(imgByteArr); emp.RestCode = "HN"; DataTable dt = _objbal.GetAllEmployeesbyRestCode(emp); using (BinaryReader br = new BinaryReader(fs)) { byte[] bytes = br.ReadBytes((Int32)fs.Length); emp.Image = bytes; string Result = _objbal.EditEmployee(emp); MessageBox.Show("Updated successfully"); GetProfile(); } } }
private void Edit_Click(object sender, RoutedEventArgs e) { string str; try { if (txtFirstName.Text == "" && txtLastName.Text == "") { MessageBox.Show("Please Load the details to edit"); } else if (txtEmailId.Text.Length == 0) { MessageBox.Show("Enter an email."); txtEmailId.Focus(); } else if (txtMobile1.Text.Length == 0) { MessageBox.Show("Enter the Mobile Number."); txtMobile1.Focus(); } else if (cmbrestcode.Text == "" || cmbrestcode.Text == null) { MessageBox.Show("Please select the Restaurant"); cmbrestcode.Focus(); } else if (cmbusercode.Text == "" || cmbusercode.Text == null) { MessageBox.Show("Please select the UserType"); cmbusercode.Focus(); } else if (cmbactive.Text == "" || cmbactive.Text == null) { MessageBox.Show("Please select the Availability"); cmbactive.Focus(); } else if (cmbusercode.SelectedIndex == 0) { MessageBox.Show("Please select the UserType"); cmbusercode.Focus(); } else if (cmbrestcode.SelectedIndex == 0) { MessageBox.Show("Please select the Restaurant"); cmbrestcode.Focus(); } else if (txtMobile2.Text.Length == 0) { MessageBox.Show("Enter the Mobile Number."); txtMobile2.Focus(); } else if (txtFileName.Text == "") { MessageBox.Show("Please Enter an Image.", "Image", MessageBoxButton.OK, MessageBoxImage.Information); txtFileName.Focus(); } else if (!Regex.IsMatch(txtEmailId.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Enter a valid email."); txtEmailId.Select(0, txtEmailId.Text.Length); txtEmailId.Focus(); } else if (!Regex.IsMatch(txtMobile1.Text, @"^\d{10}$")) { MessageBox.Show("Enter a valid Mobile Number."); txtMobile1.Select(0, txtMobile1.Text.Length); txtMobile1.Focus(); } else if (!Regex.IsMatch(txtMobile2.Text, @"^\d{10}$")) { MessageBox.Show("Enter a valid Mobile Number."); txtMobile2.Select(0, txtMobile2.Text.Length); txtMobile2.Focus(); } else { FileStream fs = new FileStream(txtFileName.Text, FileMode.Open, FileAccess.Read); byte[] imgByteArr = new byte[fs.Length]; string[] files = fs.Name.Split(new char[] { '\\' }); string fileName = files[files.Length - 1]; Stream stream = new MemoryStream(imgByteArr); SqlCommand com = new SqlCommand(); ep.EmpCode = txtEmpcod.Text; ep.First_Name = txtFirstName.Text; ep.Last_Name = txtLastName.Text; ep.Address1 = txtAddress1.Text; ep.Address2 = txtAddress2.Text; ep.Mobile1 = txtMobile1.Text; ep.Mobile2 = txtMobile2.Text; str = cmbactive.SelectionBoxItem.ToString(); ep.Active = Boolean.Parse(str); ep.RestCode = cmbrestcode.SelectedValue.ToString().Trim().ToUpper(); ep.Remarks = txtRemarks.Text; ep.UserCode = cmbusercode.SelectedValue.ToString().Trim().ToUpper(); ep.EmailId = txtEmailId.Text; using (BinaryReader br = new BinaryReader(fs)) { byte[] bytes = br.ReadBytes((Int32)fs.Length); ep.Image = bytes; string Emp = _objbal.EditEmployee(ep); MessageBox.Show("Employee updated Successfully", "Employee Details", MessageBoxButton.OK, MessageBoxImage.Information); GetEmpdetails(); Clearcontrols(); imgPhoto.Source = null; txtFileName.Text = ""; Submit.IsEnabled = true; } } } catch (Exception ex) { throw ex; } }