Created
April 4, 2013 05:31
-
-
Save faloi/5308059 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void AgregarMovimiento(string codigo, string detalle, string numComprobante, DateTime fecha, string tipoMovimiento, string deposito, string subdeposito, string destino, decimal cantidad) | |
{ | |
if (numComprobante == "") | |
{ | |
MessageBox.Show("Ingrese un número de comprobante.", "Falta ingresar comprobante", | |
MessageBoxButtons.OK, MessageBoxIcon.Error); | |
numeroComprobanteTextBox.Focus(); | |
} | |
else if ((tipoMovimiento == "Transferencia") && (deposito == destino)) | |
{ | |
MessageBox.Show("El origen y destino de la transferencia no pueden ser el mismo.", "Transferencia errónea", | |
MessageBoxButtons.OK, MessageBoxIcon.Error); | |
destinoComboBox.Focus(); | |
} | |
else | |
{ | |
bool continuar = true, yaExistia = false, nuevaTransferencia = false; | |
decimal ingresos = 0, egresos = 0; | |
if (nuevoDataGridView.RowCount > 0) | |
{ | |
string mov = nuevoDataGridView.Rows[0].Cells["TipoMovimiento"].Value.ToString(); | |
if ((tipoMovimiento == "Inventario") && (mov != "Inventario")) | |
{ | |
MessageBox.Show("No puede realizar inventarios hasta que no guarde o borre los " + nuevoDataGridView.Rows.Count.ToString() + " movimientos que cargó.", | |
"Se encontraron movimientos", MessageBoxButtons.OK, MessageBoxIcon.Information); | |
continuar = false; | |
} | |
else if ((tipoMovimiento != "Inventario") && (mov == "Inventario")) | |
{ | |
MessageBox.Show("No puede reaizar movimientos hasta que no guarde o borre los " + nuevoDataGridView.Rows.Count.ToString() + " inventarios que cargó.", | |
"Se encontraron inventarios", MessageBoxButtons.OK, MessageBoxIcon.Information); | |
continuar = false; | |
} | |
if (continuar) | |
{ | |
foreach (DataGridViewRow dr in nuevoDataGridView.Rows) | |
{ | |
if ((dr.Cells["Articulo"].Value.Equals(codigo)) | |
&& (dr.Cells["NumeroComprobante"].Value.ToString() == numComprobante) | |
&& (dr.Cells["Fecha"].Value.ToString() == fecha.ToShortDateString()) | |
&& (dr.Cells["TipoMovimiento"].Value.ToString() == tipoMovimiento) | |
&& (dr.Cells["Deposito"].Value.ToString() == deposito) | |
&& (dr.Cells["Subdeposito"].Value.ToString() == subdeposito)) | |
{ | |
if (tipoMovimiento == "Transferencia") | |
nuevaTransferencia = !(dr.Cells["Destino"].Value.Equals(destino)); | |
if (!nuevaTransferencia) | |
{ | |
yaExistia = true; | |
decimal aux = 0; | |
if (tipoMovimiento == "Transferencia") | |
{ | |
aux = Convert.ToDecimal(dr.Cells["Ingresos"].Value) + cantidad; | |
dr.Cells["Egresos"].Value = dr.Cells["Ingresos"].Value = aux.ToString("0.##"); | |
} | |
else | |
{ | |
string tipoMov; | |
if ((tipoMovimiento == "Ingreso") || (tipoMovimiento == "Inventario")) | |
{ | |
ingresos = cantidad; | |
tipoMov = "Ingresos"; | |
} | |
else | |
{ | |
egresos = cantidad; | |
tipoMov = "Egresos"; | |
} | |
aux = Convert.ToDecimal(dr.Cells[tipoMov].Value) + ingresos + egresos; | |
dr.Cells[tipoMov].Value = aux.ToString("0.##"); | |
if (tipoMovimiento != "Inventario") | |
{ | |
aux = Convert.ToDecimal(dr.Cells["Stock"].Value) + ingresos - egresos; | |
dr.Cells["Stock"].Value = aux.ToString("0.##"); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
if ((!yaExistia) && (continuar)) | |
{ | |
if (tipoMovimiento == "Inventario") | |
nuevoDataGridView.Columns["Stock"].Visible = nuevoDataGridView.Columns["Egresos"].Visible = false; | |
else | |
nuevoDataGridView.Columns["Stock"].Visible = nuevoDataGridView.Columns["Egresos"].Visible = true; | |
if (tipoMovimiento == "Egreso") | |
egresos = cantidad; | |
else | |
{ | |
bool prueba = tipoMovimiento == "Ingreso"; | |
bool prueba2 = tipoMovimiento == "Inventario"; | |
if ((tipoMovimiento == "Ingreso") || (tipoMovimiento == "Inventario")) | |
ingresos = cantidad; | |
else | |
ingresos = egresos = cantidad; | |
} | |
if (stockSQLDataSet.Articulos.FindByCodigo(codigo) != null) | |
nuevoDataGridView.Rows.Add(codigo, null, fechaDateTimePicker.Value.Date.ToShortDateString(), | |
numComprobante, tipoMovimiento, detalle, deposito, subdeposito, destino, ingresos.ToString("0.##"), egresos.ToString("0.##"), 0); | |
} | |
if (continuar) | |
{ | |
RecalcularStock(nuevoDataGridView, "Articulo", "Descripcion", "Stock", "Ingresos", "Egresos", "", "TipoMovimiento", "", false); | |
RecalcularParciales(numComprobante, tipoMovimiento, cantidad, resumenDataGridView, "Sector", "TipoMov", "StockTotal"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment