private void btnSaveClient_Click(object sender, EventArgs e) { if (update == false) { try { _entitiesCustomer.CustomerName = txtNameClient.Text; _entitiesCustomer.ClientLastName = txtLastNameClient.Text; _entitiesCustomer.ClientMaternalSurname = txtMothersLastNameClient.Text; _entitiesCustomer.DniClient = Convert.ToInt32(txtDniClient.Text); _entitiesCustomer.CustomerEmail = txtEmailClient.Text; _entitiesCustomer.PhoneClient = Convert.ToInt32(txtPhoneClient.Text); _entitiesCustomer.CustomerCivilStatus = cmbCivilStatusClient.SelectedItem.ToString(); _entitiesCustomer.CustomerGender = cmbGenderClient.SelectedItem.ToString(); _entitiesCustomer.CustomerAddress = txtAddressClient.Text; _entitiesCustomer.CustomerRegistrationDate = Convert.ToDateTime(dtDateAdmissionClient.Text); _objCustomer.InsertCustomer(_entitiesCustomer); frmSuccess = new FrmSuccess("CLIENTE REGISTRADO!"); frmSuccess.ShowDialog(); Close(); } catch (Exception ex) { MessageBox.Show("No se logro guardar el registro. " + ex.Message, "Valla, algo no anda bien"); } } if (update == true) { try { _entitiesCustomer.IdClient = Convert.ToInt32(txtIdClient.Text); _entitiesCustomer.CustomerName = txtNameClient.Text; _entitiesCustomer.ClientLastName = txtLastNameClient.Text; _entitiesCustomer.ClientMaternalSurname = txtMothersLastNameClient.Text; _entitiesCustomer.DniClient = Convert.ToInt32(txtDniClient.Text); _entitiesCustomer.CustomerEmail = txtEmailClient.Text; _entitiesCustomer.PhoneClient = Convert.ToInt32(txtPhoneClient.Text); _entitiesCustomer.CustomerCivilStatus = cmbCivilStatusClient.SelectedItem.ToString(); _entitiesCustomer.CustomerGender = cmbGenderClient.SelectedItem.ToString(); _entitiesCustomer.CustomerAddress = txtAddressClient.Text; _entitiesCustomer.CustomerRegistrationDate = Convert.ToDateTime(dtDateAdmissionClient.Text); _objCustomer.UpdateCustomer(_entitiesCustomer); frmSuccess = new FrmSuccess("CLIENTE ACTUALIZADO!"); frmSuccess.ShowDialog(); Close(); update = false; } catch (Exception ex) { MessageBox.Show("No se logro actualizar el registro. " + ex.Message, "Valla, algo no anda bien"); } } }
private void btnSaveUser_Click(object sender, EventArgs e) { if (update == false) { try { //llenamos nuestra entidad con los campos del formulario _entitiesUserManagement.IdEmployee = Convert.ToInt32(cmbNameEmployee.SelectedValue); _entitiesUserManagement.UserName = txtNameUser.Text; _entitiesUserManagement.IdRol = (cmbRolUser.SelectedIndex + 1); //la contraseña no se enviara desde el input porque la misma sera la misma para //todos los nuevos usuarios 123456789 luego se le pedira a cada usuario que //personalice su contraseña. //_entitiesUserManagement.Password = txtPassword.Text; _objUserManagement.InsertUser(_entitiesUserManagement); frmSuccess = new FrmSuccess("USUARIO GUARDADO!"); frmSuccess.ShowDialog(); Close(); } catch (Exception ex) { MessageBox.Show("No se logro guardar el registro. " + ex.Message); } } if (update == true) { try { _entitiesUserManagement.IdEmployee = Convert.ToInt32(cmbNameEmployee.SelectedValue); _entitiesUserManagement.UserName = txtNameUser.Text; _entitiesUserManagement.IdRol = (cmbRolUser.SelectedIndex + 1); _entitiesUserManagement.IdUser = Convert.ToInt32(txtIdUser.Text); _objUserManagement.UpdateUser(_entitiesUserManagement); frmSuccess = new FrmSuccess("USUARIO ACTUALIZADO!"); frmSuccess.ShowDialog(); Close(); update = false; } catch (Exception ex) { MessageBox.Show("No se logro actualizar el registro. " + ex.Message, "Valla, algo no anda bien"); } } }
private void btnSave_Click(object sender, EventArgs e) { if (update == false) { try {/* * //quiero que tenga el valor del id * cmbCivilStatus.ValueMember = "CivilStatus"; * //pero quiero que el usuario vea el nombre * cmbDepartment.DisplayMember = "CivilStatus"; * * //quiero que tenga el valor del id * cmbSex.ValueMember = "Sex"; * //pero quiero que el usuario vea el nombre * cmbSex.DisplayMember = "Sex";*/ _entities.NameEmployee = txtNameEmployee.Text; _entities.LastName = txtLastName.Text; _entities.MothersLastName = txtMothersLastName.Text; _entities.Dni = Convert.ToInt32(txtDni.Text); _entities.Email = txtEmail.Text; _entities.Phone = Convert.ToInt32(txtPhone.Text); _entities.CivilStatus = cmbCivilStatus.SelectedItem.ToString(); _entities.Sex = cmbSex.SelectedItem.ToString(); _entities.IdDepartment = Convert.ToInt32(cmbDepartment.SelectedValue); _entities.AddressEmployee = txtAddress.Text; _entities.DateOfAdmission = Convert.ToDateTime(dtDateAdmission.Text); _objBusines.InsertEmployee(_entities); frmSuccess = new FrmSuccess("EMPLEADO GUARDADO!"); frmSuccess.ShowDialog(); Close(); } catch (Exception ex) { MessageBox.Show("No se logro guardar el registro. " + ex.Message); } } if (update == true) { try { _entities.IdEmployee = Convert.ToInt32(txtIdEmployee.Text); _entities.NameEmployee = txtNameEmployee.Text; _entities.LastName = txtLastName.Text; _entities.MothersLastName = txtMothersLastName.Text; _entities.Dni = Convert.ToInt32(txtDni.Text); _entities.Email = txtEmail.Text; _entities.Phone = Convert.ToInt32(txtPhone.Text); _entities.CivilStatus = cmbCivilStatus.SelectedItem.ToString(); _entities.Sex = cmbSex.SelectedItem.ToString(); _entities.IdDepartment = Convert.ToInt32(cmbDepartment.SelectedValue); _entities.AddressEmployee = txtAddress.Text; _entities.DateOfAdmission = Convert.ToDateTime(dtDateAdmission.Text); _objBusines.UpdateEmployee(_entities); frmSuccess = new FrmSuccess("EMPLEADO ACTUALIZADO!"); frmSuccess.ShowDialog(); Close(); update = false; } catch (Exception ex) { MessageBox.Show("No se logro actualizar el registro. " + ex.Message, "Valla, algo no anda bien"); } } }
//evento-metodo- que se encarga de enviar la venta para el insert a la base de datos private void pbApplySale_Click(object sender, EventArgs e) { //realizamos la instancia de nuestra entidad y nuetro negocio. N_Sales applySale = new N_Sales(); N_SalesConcepts applySaleConcepts = new N_SalesConcepts(); E_Sales entitySale = new E_Sales(); E_SalesConcepts entitySaleConcept; try { string noNumber = txtIdCliente.Text; int number = 0; //si el cliente no existe en la venta le agregamos un valor por defecto a nuestro cliente //validamos de que la cadena sea un numero if (!int.TryParse(noNumber, out number)) { txtIdCliente.Text = "1003"; } //validamos de que el datagridview(tabla) tenga datos. if (dgvTableSales.Rows.Count == 0) { txtQuantityToSell.Focus(); lblCodeProduct.Text = "CODIGO PRODUCTO"; lblCodeProduct.ForeColor = Color.DarkGray; return; } //le pasamos los valores a nuestra entidad entitySale.IdUser = SessionUsers.IdUser; entitySale.IdClient = Int32.Parse(txtIdCliente.Text); entitySale.Total = decimal.Parse(txtTotalToPay.Text); entitySale.DateOfSale = DateTime.Now; //realizamos el envio de los datos para la insercion a la base de datos int idSale = applySale.GenerarateSalesInsert(entitySale); //si el insert se realiza exitosamente en la tabla ventas //se realizara el segundo insert a la tabla detalle de venta. if (idSale > 0) { //creamos la lista que contendra nuestra entidad E_SalesConcepts List <E_SalesConcepts> list_SalesConcepts = new List <E_SalesConcepts>(); //creamos un ciclo para recorrer cada celda de la tabla(datagridview sales) foreach (DataGridViewRow rows in dgvTableSales.Rows) { //creamos el objeto entitySaleConcept = new E_SalesConcepts(); //el tomamos el ultimo id insertado entitySaleConcept.IdSale = idSale; //buscamos en la celda a utilizar para el id del producto entitySaleConcept.IdProduct = Int32.Parse(rows.Cells[6].Value.ToString()); //buscamos en la celda a utilizar para el precio del producto entitySaleConcept.SalePrice = decimal.Parse(rows.Cells[4].Value.ToString()); //buscamos en la celda a utilizar para el total del producto. entitySaleConcept.Amount = Int32.Parse(rows.Cells[2].Value.ToString()); //llenamos la lista con nuestra entidad list_SalesConcepts.Add(entitySaleConcept); } //realizamos el segundo insert //insert a la tabla detalle de venta if (list_SalesConcepts.Count > 0) { applySaleConcepts.GenerarateSaleConceptInsert(list_SalesConcepts); //else error } //venta exitosa formSuccess = new FrmSuccess("Venta Exitosa!"); formSuccess.ShowDialog(); //luego de completar la venta limpiamos la tabla venta. //dgvTableSales.DataSource = ""; dgvTableSales.Columns.Clear(); CalculateTotal(); //limpiamos todos los campos de la venta searchDNI.Text = ""; lblCustomer.Text = "Cliente al contado"; lblAddressCustomer.Text = "Direccion Del Cliente"; } else { formErro = new FrmError("Error en la venta."); formErro.ShowDialog(); return; } } catch (Exception ex) { MessageBox.Show("algo no anda bien..." + ex); } }
private void btnSavePassword_Click(object sender, EventArgs e) { if (txtOldPassword.Text == "" || string.IsNullOrEmpty(txtOldPassword.Text)) { if (txtOldPassword.Text != "") { lblErroOldPassword.Visible = false; } lblErroOldPassword.ForeColor = System.Drawing.Color.Red; lblErroOldPassword.Visible = true; lblErroOldPassword.Text = "Campos Obligatorios"; txtOldPassword.Focus(); return; } if (txtPasswordNew.Text == "" || string.IsNullOrEmpty(txtPasswordNew.Text)) { if (!string.IsNullOrEmpty(txtOldPassword.Text)) { lblErroOldPassword.Visible = false; } if (txtPasswordNew.Text != "") { lblEerroPass.Visible = false; } lblEerroPass.ForeColor = System.Drawing.Color.Red; lblEerroPass.Visible = true; lblEerroPass.Text = "Campos Obligatorios"; txtPasswordNew.Focus(); return; } if (txtPasswordNew.Text != txtPasswordRepeat.Text) { if (txtPasswordNew.Text != "") { lblEerroPass.Visible = false; } lblErroPasswordRepeat.ForeColor = System.Drawing.Color.Red; lblErroPasswordRepeat.Visible = true; lblErroPasswordRepeat.Text = "Contraseñas NO Coinciden"; txtPasswordNew.Text = ""; txtPasswordNew.Focus(); return; } //encriptamos el password. string passwordOld = CapaDatos.EncryptPassword.GetSHA256(txtOldPassword.Text); string passwordNew = CapaDatos.EncryptPassword.GetSHA256(txtPasswordNew.Text); usersEntities = users.LoginValidate(SessionUsers.UserName, passwordOld); if (usersEntities == null) { lblErroOldPassword.ForeColor = System.Drawing.Color.Red; lblErroOldPassword.Visible = true; lblErroOldPassword.Text = "La Contraseña No Es Valida"; txtOldPassword.Focus(); } else { lblErroOldPassword.Visible = false; try { int passwordChanged = users.UpdatePassword(SessionUsers.IdUser, passwordNew); if (passwordChanged == 1) { Close(); FrmSuccess frmSuccess = new FrmSuccess("Contraseña Actualizada"); frmSuccess.ShowDialog(); } } catch (Exception es) { MessageBox.Show("error " + es.Message); } } }