Exemplo n.º 1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                var res = Helper.MensajePregunta("¿Está seguro de que la información es correcta?", GlobalClass.NombreApp);
                if (res == DialogResult.No)
                {
                    return;
                }

                SplashScreen.Show(new Splash());
                this.btnGuardar.Enabled = false;
                this.Cursor             = Cursors.WaitCursor;

                foreach (DataGridViewRow row in this.dgvDatos.Rows)
                {
                    if (Helper.ConvertirBool(row.Cells["Sel"].Value).Equals(true))
                    {
                        var parteId    = Helper.ConvertirEntero(row.Cells["ParteID"].Value);
                        var sucursalId = Helper.ConvertirEntero(row.Cells["SucursalID"].Value);

                        //Actualizar tabla ParteExistencia, campos Maximo y Minimo
                        var parteExistencia = General.GetEntity <ParteExistencia>(p => p.ParteID == parteId && p.SucursalID == sucursalId);
                        if (null != parteExistencia)
                        {
                            parteExistencia.Maximo = Helper.ConvertirEntero(row.Cells["MAX"].Value);
                            parteExistencia.Minimo = Helper.ConvertirEntero(row.Cells["MIN"].Value);
                            Guardar.Generico <ParteExistencia>(parteExistencia);
                        }

                        //Actualizar tabla Parte, campo TiempoReposicion
                        var parte = General.GetEntity <Parte>(p => p.ParteID == parteId);
                        if (null != parte)
                        {
                            parte.TiempoReposicion = Helper.ConvertirDecimal(row.Cells["TiempoReposicion"].Value);
                            Guardar.Generico <Parte>(parte);
                        }

                        var mxmn = General.GetEntity <ParteMxMn>(p => p.ParteID == parteId && p.SucursalID == sucursalId && p.Estatus);

                        int? max  = null;
                        int? min  = null;
                        bool fijo = false;
                        if (Helper.ConvertirBool(row.Cells["Fijo"].Value).Equals(true))
                        {
                            fijo = true;
                            if (!string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["MAX"].Value)))
                            {
                                max = Helper.ConvertirEntero(row.Cells["MAX"].Value);
                            }
                            if (!string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["MIN"].Value)))
                            {
                                min = Helper.ConvertirEntero(row.Cells["MIN"].Value);
                            }
                        }

                        if (null == mxmn) //Nuevo registro
                        {
                            mxmn = new ParteMxMn()
                            {
                                EsFijo     = fijo,
                                ParteID    = parteId,
                                SucursalID = sucursalId,
                                Criterio   = !string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["Criterio"].Value)) ? Helper.ConvertirCadena(row.Cells["Criterio"].Value) : null,
                                AjusteMn   = !string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["AjusteMn"].Value)) ? Helper.ConvertirCadena(row.Cells["AjusteMn"].Value) : null,
                                AjusteMx   = !string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["AjusteMx"].Value)) ? Helper.ConvertirCadena(row.Cells["AjusteMx"].Value) : null,
                                Maximo     = max,
                                Minimo     = min
                            };
                        }
                        else
                        {
                            mxmn.EsFijo   = fijo;
                            mxmn.Criterio = Helper.ConvertirCadena(row.Cells["Criterio"].Value);
                            mxmn.AjusteMn = Helper.ConvertirCadena(row.Cells["AjusteMn"].Value);
                            mxmn.AjusteMx = Helper.ConvertirCadena(row.Cells["AjusteMx"].Value);
                            mxmn.Maximo   = max;
                            mxmn.Minimo   = min;
                        }
                        Guardar.Generico <ParteMxMn>(mxmn);
                        this.actualizarParteMxMnCriterio(mxmn.ParteMxMnID, Helper.ConvertirCadena(row.Cells["CriteriosGenerales"].Value));
                    }
                }

                this.Cursor = Cursors.Default;
                SplashScreen.Close();
                this.btnGuardar.Enabled = true;
                new Notificacion("Información almacenada correctamente.", 2 * 1000).Mostrar(Principal.Instance);
                this.CargaInicial();
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                SplashScreen.Close();
                this.btnGuardar.Enabled = true;
                Helper.MensajeError(ex.Message, GlobalClass.NombreApp);
            }
        }
Exemplo n.º 2
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                var res = Helper.MensajePregunta("¿Está seguro de que la información es correcta?", GlobalClass.NombreApp);
                if (res == DialogResult.No)
                    return;

                SplashScreen.Show(new Splash());
                this.btnGuardar.Enabled = false;
                this.Cursor = Cursors.WaitCursor;

                foreach (DataGridViewRow row in this.dgvDatos.Rows)
                {
                    if (Helper.ConvertirBool(row.Cells["Sel"].Value).Equals(true))
                    {
                        var parteId = Helper.ConvertirEntero(row.Cells["ParteID"].Value);
                        var sucursalId = Helper.ConvertirEntero(row.Cells["SucursalID"].Value);

                        //Actualizar tabla ParteExistencia, campos Maximo y Minimo
                        var parteExistencia = General.GetEntity<ParteExistencia>(p => p.ParteID == parteId && p.SucursalID == sucursalId);
                        if (null != parteExistencia)
                        {
                            parteExistencia.Maximo = Helper.ConvertirEntero(row.Cells["MAX"].Value);
                            parteExistencia.Minimo = Helper.ConvertirEntero(row.Cells["MIN"].Value);
                            Guardar.Generico<ParteExistencia>(parteExistencia);
                        }

                        //Actualizar tabla Parte, campo TiempoReposicion
                        var parte = General.GetEntity<Parte>(p => p.ParteID == parteId);
                        if (null != parte)
                        {
                            parte.TiempoReposicion = Helper.ConvertirDecimal(row.Cells["TiempoReposicion"].Value);
                            Guardar.Generico<Parte>(parte);
                        }

                        var mxmn = General.GetEntity<ParteMxMn>(p => p.ParteID == parteId && p.SucursalID == sucursalId && p.Estatus);

                        int? max = null;
                        int? min = null;
                        bool fijo = false;
                        if (Helper.ConvertirBool(row.Cells["Fijo"].Value).Equals(true))
                        {
                            fijo = true;
                            if (!string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["MAX"].Value)))
                                max = Helper.ConvertirEntero(row.Cells["MAX"].Value);
                            if (!string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["MIN"].Value)))
                                min = Helper.ConvertirEntero(row.Cells["MIN"].Value);
                        }

                        if (null == mxmn) //Nuevo registro
                        {
                            mxmn = new ParteMxMn()
                            {
                                EsFijo = fijo,
                                ParteID = parteId,
                                SucursalID = sucursalId,
                                Criterio = !string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["Criterio"].Value)) ? Helper.ConvertirCadena(row.Cells["Criterio"].Value) : null,
                                AjusteMn = !string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["AjusteMn"].Value)) ? Helper.ConvertirCadena(row.Cells["AjusteMn"].Value) : null,
                                AjusteMx = !string.IsNullOrEmpty(Helper.ConvertirCadena(row.Cells["AjusteMx"].Value)) ? Helper.ConvertirCadena(row.Cells["AjusteMx"].Value) : null,
                                Maximo = max,
                                Minimo = min
                            };
                        }
                        else
                        {
                            mxmn.EsFijo = fijo;
                            mxmn.Criterio = Helper.ConvertirCadena(row.Cells["Criterio"].Value);
                            mxmn.AjusteMn = Helper.ConvertirCadena(row.Cells["AjusteMn"].Value);
                            mxmn.AjusteMx = Helper.ConvertirCadena(row.Cells["AjusteMx"].Value);
                            mxmn.Maximo = max;
                            mxmn.Minimo = min;
                        }
                        Guardar.Generico<ParteMxMn>(mxmn);
                        this.actualizarParteMxMnCriterio(mxmn.ParteMxMnID, Helper.ConvertirCadena(row.Cells["CriteriosGenerales"].Value));
                    }
                }

                this.Cursor = Cursors.Default;
                SplashScreen.Close();
                this.btnGuardar.Enabled = true;
                new Notificacion("Información almacenada correctamente.", 2 * 1000).Mostrar(Principal.Instance);
                this.CargaInicial();
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                SplashScreen.Close();
                this.btnGuardar.Enabled = true;
                Helper.MensajeError(ex.Message, GlobalClass.NombreApp);
            }
        }