Exemple #1
0
        public bool Existekardex(E_Kardex ObjE_Kardex)
        {
            bool      Existe       = true;
            CD_Kardex ObjCD_Kardex = new CD_Kardex(AppSettings.GetConnectionString);
            DataTable dtTMP        = new DataTable();

            Existe = ObjCD_Kardex.Existekardex(ObjE_Kardex);
            return(Existe);
        }
Exemple #2
0
        public int InsertKardex(E_Kardex ObjE_Kardex, DataTable DtKardex, string Tipo)
        {
            int       KardexID     = 0;
            CD_Kardex ObjCD_Kardex = new CD_Kardex(AppSettings.GetConnectionString);
            DataTable dtTMP        = new DataTable();

            string XML = "";

            if (Tipo == "M")
            {
                string _xml = new BaseFunctions().GetXML(DtKardex).Replace("NewDataSet", "DocumentElement");
                XML = _xml.Replace("Table", "Kardex");
            }

            KardexID = ObjCD_Kardex.InsertKardex(ObjE_Kardex, XML, Tipo);
            return(KardexID);
        }
Exemple #3
0
        public int InsertKardex(E_Kardex ObjE_Kardex, string Xml, string Tipo)
        {
            SqlDatabase SqlClient = new SqlDatabase(connectionString);

            DbConnection tCnn;

            tCnn = SqlClient.CreateConnection();
            tCnn.Open();

            DbTransaction tran = tCnn.BeginTransaction();

            try
            {
                int       KardexID   = 0;
                DbCommand SqlCommand = SqlClient.GetStoredProcCommand("[Almacen].[Usp_InsertKardex]");
                SqlClient.AddInParameter(SqlCommand, "@AlmacenID", SqlDbType.Char, ObjE_Kardex.AlmacenID);
                SqlClient.AddInParameter(SqlCommand, "@AlmacenExterno", SqlDbType.Char, ObjE_Kardex.AlmacenExterno);
                SqlClient.AddInParameter(SqlCommand, "@ProductoID", SqlDbType.VarChar, ObjE_Kardex.ProductoID);
                SqlClient.AddInParameter(SqlCommand, "@Cantidad", SqlDbType.Decimal, ObjE_Kardex.Cantidad);
                SqlClient.AddInParameter(SqlCommand, "@MovimientoID", SqlDbType.TinyInt, ObjE_Kardex.MovimientoID);
                SqlClient.AddInParameter(SqlCommand, "@TipoComprobante", SqlDbType.Char, ObjE_Kardex.TipoComprobante);
                SqlClient.AddInParameter(SqlCommand, "@Serie", SqlDbType.VarChar, ObjE_Kardex.Serie);
                SqlClient.AddInParameter(SqlCommand, "@Numero", SqlDbType.Int, ObjE_Kardex.Numero);
                SqlClient.AddInParameter(SqlCommand, "@TipoOperacion", SqlDbType.Char, ObjE_Kardex.TipoOperacion);
                SqlClient.AddInParameter(SqlCommand, "@CostoUnitario", SqlDbType.Decimal, ObjE_Kardex.CostoUnitario);
                SqlClient.AddInParameter(SqlCommand, "@Ingreso", SqlDbType.Char, ObjE_Kardex.Ingreso);
                SqlClient.AddInParameter(SqlCommand, "@UsuarioID", SqlDbType.Int, ObjE_Kardex.UsuarioID);
                SqlClient.AddInParameter(SqlCommand, "@AudCrea", SqlDbType.SmallDateTime, ObjE_Kardex.AudCrea);
                SqlClient.AddInParameter(SqlCommand, "@XML", SqlDbType.Xml, Xml);
                SqlClient.AddInParameter(SqlCommand, "@Tipo", SqlDbType.Char, Tipo);
                KardexID = Convert.ToInt32(SqlClient.ExecuteScalar(SqlCommand, tran));
                SqlCommand.Dispose();

                tran.Commit();
                tCnn.Close();
                tCnn.Dispose();

                return(KardexID);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw new Exception(ex.Message);
            }
        }
Exemple #4
0
        public bool Existekardex(E_Kardex ObjE_Kardex)
        {
            SqlDatabase SqlClient = new SqlDatabase(connectionString);

            DbConnection tCnn;

            tCnn = SqlClient.CreateConnection();
            tCnn.Open();

            DbTransaction tran = tCnn.BeginTransaction();

            try
            {
                bool      Existe     = true;
                DbCommand SqlCommand = SqlClient.GetStoredProcCommand("[Almacen].[Usp_Existekardex]");
                SqlClient.AddInParameter(SqlCommand, "@AlmacenID", SqlDbType.Char, ObjE_Kardex.AlmacenID);
                SqlClient.AddInParameter(SqlCommand, "@ProductoID", SqlDbType.VarChar, ObjE_Kardex.ProductoID);
                SqlClient.AddInParameter(SqlCommand, "@TipoComprobante", SqlDbType.Char, ObjE_Kardex.TipoComprobante);
                SqlClient.AddInParameter(SqlCommand, "@Serie", SqlDbType.Char, ObjE_Kardex.Serie);
                SqlClient.AddInParameter(SqlCommand, "@Numero", SqlDbType.Int, ObjE_Kardex.Numero);
                SqlClient.AddInParameter(SqlCommand, "@TipoOperacion", SqlDbType.Char, ObjE_Kardex.TipoOperacion);
                Existe = Convert.ToBoolean(SqlClient.ExecuteScalar(SqlCommand, tran));
                SqlCommand.Dispose();

                tran.Commit();
                tCnn.Close();
                tCnn.Dispose();

                return(Existe);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw new Exception(ex.Message);
            }
        }
        private void BtnIngresar_Click(object sender, EventArgs e)
        {
            //ingresar movimiento del producto
            try
            {
                Errp.Clear();
                //validar
                if (CboAlmacen.SelectedIndex != -1 & CboMovimiento.SelectedIndex != -1 & CboOperacion.SelectedIndex != -1 &
                    CboProducto.SelectedIndex != -1 & CboSede.SelectedIndex != -1 & CboTipoDocumento.SelectedIndex != -1 &
                    TxtCantidad.Text != "" & TxtCostoUnitario.Text != "" & TxtNumero.Text != "" & TxtSerie.Text != "" &
                    TxtSerie.Text.Length == 3 & DtKardex.Rows.Count > 0)
                {
                    //2da validacion
                    if (Convert.ToDecimal(TxtCantidad.Text) != 0 & Convert.ToInt32(TxtNumero.Text) != 0)
                    {
                        int       KardexID     = 0;
                        CL_Kardex ObjCL_Kardex = new CL_Kardex();
                        E_Kardex  ObjE_Kardex  = new E_Kardex();
                        ObjE_Kardex.AlmacenID       = DtKardex.Rows[0]["AlmacenID"].ToString();
                        ObjE_Kardex.ProductoID      = DtKardex.Rows[0]["ProductoID"].ToString();
                        ObjE_Kardex.MovimientoID    = Convert.ToInt32(CboMovimiento.SelectedValue);
                        ObjE_Kardex.TipoComprobante = CboTipoDocumento.SelectedValue.ToString();
                        ObjE_Kardex.Cantidad        = Convert.ToDecimal(DtKardex.Rows[0]["Cantidad"]);
                        ObjE_Kardex.Serie           = TxtSerie.Text;
                        ObjE_Kardex.Numero          = Convert.ToInt32(TxtNumero.Text);
                        ObjE_Kardex.TipoOperacion   = CboOperacion.SelectedValue.ToString();
                        ObjE_Kardex.CostoUnitario   = Convert.ToDecimal(DtKardex.Rows[0]["CostoUnitario"]);
                        ObjE_Kardex.Ingreso         = "M";
                        ObjE_Kardex.UsuarioID       = AppSettings.UserID;
                        ObjE_Kardex.AudCrea         = Convert.ToDateTime(DtFecha.Value.ToShortDateString());
                        //verificar si existe el movimiento, si no existe se ingresa, en caso de existir pregunta al usuario
                        bool existe = true;
                        existe = ObjCL_Kardex.Existekardex(ObjE_Kardex);
                        if (existe == false)
                        {
                            if (DtKardex.Rows.Count == 1)
                            {
                                KardexID = ObjCL_Kardex.InsertKardex(ObjE_Kardex, null, "U");
                            }
                            else
                            {
                                KardexID = ObjCL_Kardex.InsertKardex(ObjE_Kardex, DtKardex, "M");
                            }
                        }
                        else
                        {
                            if (MessageBox.Show("El movimiento ya existe.\n\n¿Desea ingresarlo de todos modos?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                if (DtKardex.Rows.Count == 1)
                                {
                                    KardexID = ObjCL_Kardex.InsertKardex(ObjE_Kardex, null, "U");
                                }
                                else
                                {
                                    KardexID = ObjCL_Kardex.InsertKardex(ObjE_Kardex, DtKardex, "M");
                                }
                                existe = false;
                            }
                            else
                            {
                                return;
                            }
                        }
                        ObjE_Kardex.KardexID = KardexID;
                        if (DtKardex.Rows.Count == 1)
                        {
                            #region Agregar a la tabla temp del formulario Re_Kardex
                            if (Rep_Kardex.DtTemp.Rows.Count > 0 & existe == false)
                            {
                                DataRow DR = Rep_Kardex.DtTemp.NewRow();
                                DR["KardexID"]           = ObjE_Kardex.KardexID;
                                DR["Tabla"]              = "K";
                                DR["AudCrea"]            = ObjE_Kardex.AudCrea;
                                DR["ProductoID"]         = ObjE_Kardex.ProductoID;
                                DR["Producto"]           = CboProducto.Columns["Alias"].Value.ToString();
                                DR["UMContabilidad"]     = "";
                                DR["UnidadMedidaID"]     = CboProducto.Columns["UnidadMedidaID"].Value.ToString();
                                DR["Cantidad"]           = ObjE_Kardex.Cantidad;
                                DR["CantidadReal"]       = ObjE_Kardex.Cantidad;
                                DR["TipoContabilidad"]   = ObjE_Kardex.TipoComprobante;
                                DR["Serie"]              = ObjE_Kardex.Serie;
                                DR["Numero"]             = ObjE_Kardex.Numero;
                                DR["TipoOperacion"]      = ObjE_Kardex.TipoOperacion;
                                DR["Tipo"]               = CboMovimiento.Columns["Tipo"].Value.ToString();
                                DR["PrecioUnitario"]     = ObjE_Kardex.CostoUnitario;
                                DR["NomMovimiento"]      = CboMovimiento.Columns["NomMovimiento"].Value.ToString();
                                DR["TipoExistencia"]     = "ACTUALIZAR PARA VISUALIZAR";
                                DR["FactorConversion"]   = 0;
                                DR["Unidades"]           = 0;
                                DR["MovimientoID"]       = ObjE_Kardex.MovimientoID;
                                DR["UnidadMedidaIDReal"] = CboProducto.Columns["UnidadMedidaID"].Value;
                                DR["PresentacionReal"]   = "ACTUALIZAR PARA VISUALIZAR";
                                DR["Establecimiento"]    = 9999;
                                DR["Orden"]              = 0;
                                Rep_Kardex.DtTemp.Rows.Add(DR);
                            }
                            #endregion
                            MessageBox.Show("Se almaceno correctamente el movimiento.\r\nEl ID generado es: " + KardexID.ToString(), "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Se almaceno correctamente el movimiento.\r\nEl ID generado es: " + KardexID.ToString() + ".\r\nEn este caso por ser insercion masiva debe\nvolver a consultra los datos para\npoder ver la actualización.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        DtKardex.Rows.Clear();
                    }
                    else
                    {
                        if (Convert.ToDecimal(TxtCantidad.Text) == 0)
                        {
                            Errp.SetError(TxtCantidad, "Ingrese una cantidad valida diferente de cero.");
                        }
                        //if (Convert.ToDecimal(TxtCostoUnitario.Text) == 0) Errp.SetError(TxtCostoUnitario, "Ingrese un costo valido diferente de cero.");
                        if (Convert.ToInt32(TxtNumero.Text) == 0)
                        {
                            Errp.SetError(TxtNumero, "Ingrese un número valido diferente de cero.");
                        }
                    }
                }
                else
                {
                    if (CboAlmacen.SelectedIndex == -1)
                    {
                        Errp.SetError(CboAlmacen, "Seleccione un almacen.");
                    }
                    if (CboMovimiento.SelectedIndex == -1)
                    {
                        Errp.SetError(CboMovimiento, "Seleccione un movimiento.");
                    }
                    if (CboOperacion.SelectedIndex == -1)
                    {
                        Errp.SetError(CboOperacion, "Seleccione una operacion.");
                    }
                    if (CboProducto.SelectedIndex == -1)
                    {
                        Errp.SetError(CboProducto, "Seleccione una producto.");
                    }
                    if (CboSede.SelectedIndex == -1)
                    {
                        Errp.SetError(CboSede, "Seleccione una Sede.");
                    }
                    if (CboTipoDocumento.SelectedIndex == -1)
                    {
                        Errp.SetError(CboTipoDocumento, "Seleccione un tipo de documento.");
                    }
                    if (TxtCantidad.Text == "")
                    {
                        Errp.SetError(TxtCantidad, "Ingrese una cantidad valida.");
                    }
                    if (TxtCostoUnitario.Text == "")
                    {
                        Errp.SetError(TxtCostoUnitario, "Ingrese un costo valido.");
                    }
                    if (TxtNumero.Text == "")
                    {
                        Errp.SetError(TxtNumero, "Ingrese un número valido.");
                    }
                    if (TxtSerie.Text == "" | TxtSerie.Text.Length != 3)
                    {
                        Errp.SetError(TxtSerie, "Ingrese una serie valida.");
                    }
                    if (DtKardex.Rows.Count == 0)
                    {
                        Errp.SetError(TdgProductos, "No ha ingresado ningún producto a la grilla.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Metodo Ingresar\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }