public CuentaForm(Cuenta item) { InitializeComponent(); dbSIC = new DBSIC(); dbUser = new DBUsuario(); dbCuenta = new DBCuenta(); ACCION = eOperacion.UPDATE; SELECTED = item; }
public bool insert(Cuenta cuenta, string sucursal, string empleado, string sistema) { bool OK = true; try { string sql = "ddsic.SP_INSERT_CUENTA"; MySqlCommand cmd = new MySqlCommand(sql, conn.conection); cmd.CommandType = CommandType.StoredProcedure; MySqlParameter codigo = cmd.Parameters.Add("codigo", MySqlDbType.VarChar, 15); codigo.Direction = ParameterDirection.Input; MySqlParameter nombre_cta = cmd.Parameters.Add("nombre_cta", MySqlDbType.VarChar, 100); nombre_cta.Direction = ParameterDirection.Input; MySqlParameter mayor_cta = cmd.Parameters.Add("mayor_cta", MySqlDbType.VarChar, 15); mayor_cta.Direction = ParameterDirection.Input; MySqlParameter saldo_cta = cmd.Parameters.Add("saldo_cta", MySqlDbType.VarChar, 1); saldo_cta.Direction = ParameterDirection.Input; MySqlParameter cat_cta = cmd.Parameters.Add("cat_cta", MySqlDbType.VarChar,1); cat_cta.Direction = ParameterDirection.Input; MySqlParameter tipo_cta = cmd.Parameters.Add("tipo_cta", MySqlDbType.Int32); tipo_cta.Direction = ParameterDirection.Input; MySqlParameter suc = cmd.Parameters.Add("suc", MySqlDbType.VarChar, 2); suc.Direction = ParameterDirection.Input; MySqlParameter emp = cmd.Parameters.Add("emp", MySqlDbType.VarChar, 15); emp.Direction = ParameterDirection.Input; MySqlParameter sys = cmd.Parameters.Add("sys", MySqlDbType.VarChar, 20); sys.Direction = ParameterDirection.Input; codigo.Value = cuenta.COD_CTA; nombre_cta.Value = cuenta.NOMBRE; mayor_cta.Value = cuenta.MAYOR; saldo_cta.Value = cuenta.SALDO; cat_cta.Value = cuenta.CATEGORIA; tipo_cta.Value = (int)cuenta.TIPO; suc.Value = sucursal; emp.Value = empleado; sys.Value = sistema; cmd.ExecuteNonQuery(); MessageBox.Show("CUENTA REGISTRADA EN EL CATALOGO", "OPERACION FINALIZADA", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { OK = false; MessageBox.Show(ex.Message, "ERROR AL REGISTRAR CUENTA", MessageBoxButtons.OK, MessageBoxIcon.Error); } return OK; }
public static Cuenta ConvertToCuenta(DataRow dr) { Cuenta cuenta = null; if (dr != null) { cuenta = new Cuenta(); if (dr.Table.Columns.Contains("COD_CTA")) { cuenta.COD_CTA = dr.Field<string>("COD_CTA"); } if (dr.Table.Columns.Contains("NOMBRE")) { cuenta.NOMBRE = dr.Field<string>("NOMBRE"); } if (dr.Table.Columns.Contains("MAYOR")) { cuenta.MAYOR = dr.Field<string>("MAYOR"); } if (dr.Table.Columns.Contains("SALDO")) { cuenta.SALDO = (eSaldoCuenta)Char.ConvertToUtf32(dr.Field<string>("SALDO"), 0); } if (dr.Table.Columns.Contains("CATEGORIA")) { cuenta.CATEGORIA = (eCategoriaCuenta)Char.ConvertToUtf32(dr.Field<string>("CATEGORIA"), 0); } if (dr.Table.Columns.Contains("TIPO")) { cuenta.TIPO = (eTipoCuenta)dr.Field<int>("TIPO"); } if (dr.Table.Columns.Contains("ACTIVA")) { cuenta.ACTIVA = dr.Field<bool>("ACTIVA"); } if (dr.Table.Columns.Contains("CLASE")) { cuenta.CLASE = (eClaseCuenta)Enum.Parse(typeof(eClaseCuenta), dr.Field<string>("CLASE")); } } return cuenta; }
private void GUARDAR_Click(object sender, EventArgs e) { Cuenta c = new Cuenta(); switch (ACCION) { case eOperacion.INSERT: if (validar()) { c = buildCuenta(); string autorizacion = Controles.InputBoxPassword("CODIGO", "CODIGO DE AUTORIZACION"); if (autorizacion != "" && DBSIC.md5(autorizacion) == HOME.Instance().USUARIO.PASSWORD) { if (dbCuenta.insert(c, Properties.Settings.Default.SUCURSAL, HOME.Instance().USUARIO.COD_EMPLEADO, Properties.Settings.Default.SISTEMA)) { CatalogoCuentaForm.Instance().cargarDatos(); this.Close(); } } else { MessageBox.Show("CODIGO DE AUTORIZACION INVALIDO", "DENEGADO", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } break; case eOperacion.UPDATE: if (validar()) { c = buildCuenta(); c.COD_CTA = SELECTED.COD_CTA; string autorizacion = Controles.InputBoxPassword("CODIGO", "CODIGO DE AUTORIZACION"); if (autorizacion != "" && DBSIC.md5(autorizacion) == HOME.Instance().USUARIO.PASSWORD) { if (dbCuenta.update(c, Properties.Settings.Default.SUCURSAL, HOME.Instance().USUARIO.COD_EMPLEADO, Properties.Settings.Default.SISTEMA)) { CatalogoCuentaForm.Instance().cargarDatos(); this.Close(); } } else { MessageBox.Show("CODIGO DE AUTORIZACION INVALIDO", "DENEGADO", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } break; } }
public Cuenta buildCuenta() { Cuenta c = new Cuenta(); c.COD_CTA = txtCodigo.Text.Trim(); c.NOMBRE = txtNombreCta.Text.Trim(); if (cbxMayor.SelectedIndex > 0) { c.MAYOR = (string)cbxMayor.SelectedValue; } c.CATEGORIA = (eCategoriaCuenta)cbxCategoria.SelectedItem; c.TIPO = (eTipoCuenta)cbxTipo.SelectedItem; c.SALDO = (eSaldoCuenta)cbxSaldo.SelectedItem; return c; }
private void openFileCatalogo_FileOk(object sender, CancelEventArgs e) { progreso.Minimum = 0; progreso.Value = 0; string filePath = openFileCatalogo.FileName; string extension = Path.GetExtension(filePath); string header = "YES"; string conStr; string sheetName = "CATALOGO"; int f = 1; conStr = string.Empty; switch (extension) { case ".xls": //Excel 97-03 conStr = string.Format(Excel03ConString, filePath, header); break; case ".xlsx": //Excel 07 conStr = string.Format(Excel07ConString, filePath, header); break; } try { OleDbConnection conn = new OleDbConnection(conStr); OleDbDataAdapter ada = new OleDbDataAdapter("SELECT * From [" + sheetName + "$] ", conn); DataTable dt = new DataTable(); ada.Fill(dt); progreso.Maximum = dt.Rows.Count; if (dt.Rows.Count <= 1) { MessageBox.Show("No hay datos que importar", "ERROR AL IMPORTAR ARCHIVO", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { foreach (DataRow row in dt.Rows) { Cuenta cuenta = new Cuenta(); if (existCUENTA(row.Field<string>("CODIGO"))) { throw new Exception("CUENTA " + row.ItemArray[0].ToString() + " ya existe en el catalogo"); } else { cuenta.COD_CTA = row.Field<string>("CODIGO"); cuenta.NOMBRE = row.Field<string>("CUENTA").Replace('&','y').Replace('>',' '); cuenta.MAYOR = row.Field<string>("MAYOR"); switch (row.Field<string>("CATEGORIA").ToUpper()) { case "A": cuenta.CATEGORIA = eCategoriaCuenta.ACTIVO; break; case "ACTIVO": cuenta.CATEGORIA = eCategoriaCuenta.ACTIVO; break; case "P": cuenta.CATEGORIA = eCategoriaCuenta.PASIVO; break; case "PASIVO": cuenta.CATEGORIA = eCategoriaCuenta.PASIVO; break; case "C": cuenta.CATEGORIA = eCategoriaCuenta.CAPITAL; break; case "CAPITAL": cuenta.CATEGORIA = eCategoriaCuenta.CAPITAL; break; case "E": cuenta.CATEGORIA = eCategoriaCuenta.EGRESO; break; case "EGRESO": cuenta.CATEGORIA = eCategoriaCuenta.EGRESO; break; case "I": cuenta.CATEGORIA = eCategoriaCuenta.INGRESO; break; case "INGRESO": cuenta.CATEGORIA = eCategoriaCuenta.INGRESO; break; case "L": cuenta.CATEGORIA = eCategoriaCuenta.LIQUIDACION; break; case "LIQUIDACION": cuenta.CATEGORIA = eCategoriaCuenta.LIQUIDACION; break; case "O": cuenta.CATEGORIA = eCategoriaCuenta.ORDEN; break; case "ORDEN": cuenta.CATEGORIA = eCategoriaCuenta.ORDEN; break; default: throw new Exception("ERROR CATEGORIA INVALIDA PARA LA CUENTA " + cuenta.COD_CTA); } eTipoCuenta t; string x = row.Field<string>("TIPO"); if (x != null && x != string.Empty) { x = x.Trim().Replace(" ", "_").ToUpper(); } if (Enum.TryParse(x, out t)) { cuenta.TIPO = t; } else { cuenta.TIPO = eTipoCuenta.ND; } switch (row.Field<string>("SALDO").ToUpper()) { case "A": cuenta.SALDO = eSaldoCuenta.ACREEDOR; break; case "ACREEDOR": cuenta.SALDO = eSaldoCuenta.ACREEDOR; break; case "D": cuenta.SALDO = eSaldoCuenta.DEUDOR; break; case "DEUDOR": cuenta.SALDO = eSaldoCuenta.DEUDOR; break; default: throw new Exception("ERROR SALDO INVALIDO EN CUENTA " + cuenta.COD_CTA); } IMPORT.Rows.Add(cuenta.COD_CTA, cuenta.NOMBRE, cuenta.MAYOR, cuenta.SALDO.ToString()[0], cuenta.CATEGORIA.ToString()[0], (int)cuenta.TIPO); f++; progreso.Value = IMPORT.Rows.Count * 100 / dt.Rows.Count; } } tblCATALOGO.DataSource = IMPORT; } progreso.Value = 100; } catch (Exception ex) { MessageBox.Show("Error al importar fila " + f + "\nDetalle:" + ex.Message, "ERROR AL IMPORTAR ARCHIVO", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool delete(Cuenta cuenta, string sucursal, string empleado, string sistema) { bool OK = true; try { string sql = "ddsic.SP_DELETE_CUENTA"; MySqlCommand cmd = new MySqlCommand(sql, conn.conection); cmd.CommandType = CommandType.StoredProcedure; MySqlParameter codigo = cmd.Parameters.Add("codigo", MySqlDbType.VarChar, 15); codigo.Direction = ParameterDirection.Input; MySqlParameter suc = cmd.Parameters.Add("suc", MySqlDbType.VarChar, 2); suc.Direction = ParameterDirection.Input; MySqlParameter emp = cmd.Parameters.Add("emp", MySqlDbType.VarChar, 15); emp.Direction = ParameterDirection.Input; MySqlParameter sys = cmd.Parameters.Add("sys", MySqlDbType.VarChar, 20); sys.Direction = ParameterDirection.Input; codigo.Value = cuenta.COD_CTA; suc.Value = sucursal; emp.Value = empleado; sys.Value = sistema; cmd.ExecuteNonQuery(); MessageBox.Show("CUENTA CON CODIGO: " + cuenta + " ELIMINADA DEL CATALOGO", "OPERACION FINALIZADA", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { OK = false; MessageBox.Show(ex.Message, "ERROR AL ELIMINAR CUENTA DE CATALOGO", MessageBoxButtons.OK, MessageBoxIcon.Error); } return OK; }
private void cargarSelected() { SELECTED = new Cuenta(); if (tblCatalogo.CurrentCell != null) { SELECTED = Cuenta.ConvertToCuenta(CATALOGO.Rows[tblCatalogo.CurrentCell.RowIndex]); btnEditar.Enabled = true; btnCambiarKEY.Enabled = true; btnCambiarEstado.Enabled = true; btnEliminar.Enabled = true; } }