Exemplo n.º 1
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            bool   _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);
            string _Message    = "No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.";
            string _Title      = "Conexión de Red";

            if (_Connection)
            {
                int          Row     = DtCruces.CurrentCell.RowIndex;
                int          IDCruce = Convert.ToInt32(DtCruces.Rows[Row].Cells[0].Value.ToString());
                DialogResult dialogo = MessageBox.Show("Desea eliminar el cruce número " + IDCruce.ToString() + "?",
                                                       "Confirme", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dialogo == DialogResult.Yes)
                {
                    _Message = ((cmbTipo.SelectedIndex == 0) ? "- Debe seleccionar un tipo de plantilla" : "");
                    if (_Message.Length > 0)
                    {
                        MessageBox.Show(_Message, "Información Faltante", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    DialogResult _response = DialogResult.None;

                    oCruce _Template = new oCruce()
                    {
                        IdCruce         = IDCruce,
                        IdTipoPlantilla = cmbTipo.SelectedIndex,
                        Concepto        = "",
                        Formula         = "",
                        Condicion       = "",
                        Nota            = "",
                        LecturaImportes = 0
                    };
                    KeyValuePair <bool, string[]> _result = new lCrucesAdmin(_Template, "E").Delete();
                    string _Messages = "";
                    foreach (string _Msg in _result.Value)
                    {
                        _Messages += ((_Messages.Length > 0) ? "\r\n" : "") + _Msg;
                    }
                    if (_result.Key && _response != DialogResult.Yes)
                    {
                        _Messages = "Cruce eliminado con éxito";
                    }
                    MessageBox.Show(_Messages, (_result.Key) ? "Proceso Existoso" : "Información Faltante", MessageBoxButtons.OK, (_result.Key) ? MessageBoxIcon.Information : MessageBoxIcon.Exclamation);
                    if (_result.Key)
                    {
                        this.Hide();
                    }
                }
            }
            else
            {
                MessageBox.Show(_Message, _Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public FormulasComprobaciones()
        {
            string _Path       = Configuration.Path;
            bool   _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);
            string _Message    = "No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.";

            InitializeComponent();

            if (Directory.Exists(_Path + "\\jsons") && Directory.Exists(_Path + "\\templates"))
            {
                if (File.Exists(_Path + "\\jsons\\Comprobaciones.json"))
                {
                    if (_Connection)
                    {
                        KeyValuePair <bool, System.Data.DataTable> _TipoPlantilla = new lSerializados().ObtenerUpdate();

                        foreach (DataRow _Row in _TipoPlantilla.Value.Rows)
                        {
                            string _IdTipoPlantilla    = _Row["IdTipoPlantilla"].ToString();
                            string _Fecha_Modificacion = _Row["Fecha_Modificacion"].ToString();
                            string _Linea = null;

                            if (File.Exists(_Path + "\\jsons\\Update" + _IdTipoPlantilla + ".txt"))
                            {
                                StreamReader sw = new StreamReader(_Path + "\\Jsons\\Update" + _IdTipoPlantilla + ".txt");
                                _Linea = sw.ReadLine();
                                sw.Close();

                                if (_Linea != null)
                                {
                                    if (_Linea != _Fecha_Modificacion)
                                    {
                                        this.TopMost = false;
                                        this.Enabled = false;
                                        this.Hide();
                                        FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                                        _FileJsonfrm._Form    = this;
                                        _FileJsonfrm._Process = false;
                                        _FileJsonfrm._Update  = true;
                                        _FileJsonfrm._window  = this.Text;
                                        _FileJsonfrm.Show();
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (!_Connection)
                    {
                        MessageBox.Show(_Message.Replace("...", ", para crear los archivos base..."), "Creación de Archivos Base", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.btnGenerar.Enabled = false;
                        return;
                    }
                    else
                    {
                        this.TopMost = false;
                        this.Enabled = false;
                        this.Hide();
                        FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                        _FileJsonfrm._Form    = this;
                        _FileJsonfrm._Process = false;
                        _FileJsonfrm._Update  = false;
                        _FileJsonfrm._window  = this.Text;
                        _FileJsonfrm.Show();
                        return;
                    }
                }
            }
            else
            {
                if (!Directory.Exists(_Path + "\\jsons"))
                {
                    Directory.CreateDirectory(_Path + "\\jsons");
                }
                if (!Directory.Exists(_Path + "\\templates"))
                {
                    Directory.CreateDirectory(_Path + "\\templates");
                }

                this.TopMost = false;
                this.Enabled = false;
                this.Hide();
                FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                _FileJsonfrm._Form    = this;
                _FileJsonfrm._Process = false;
                _FileJsonfrm._window  = this.Text;
                _FileJsonfrm.Show();
                return;
            }
        }
Exemplo n.º 3
0
        public CrucesAdmin()
        {
            string _Path       = Configuration.Path;
            bool   _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);
            string _Message    = "No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.";

            InitializeComponent();

            if (Directory.Exists(_Path + "\\jsons") && Directory.Exists(_Path + "\\templates"))
            {
                if (File.Exists(_Path + "\\jsons\\TiposPlantillas.json"))
                {
                    if (_Connection)
                    {
                        KeyValuePair <bool, System.Data.DataTable> _TipoPlantilla = new lSerializados().ObtenerUpdate();

                        foreach (DataRow _Row in _TipoPlantilla.Value.Rows)
                        {
                            string _IdTipoPlantilla    = _Row["IdTipoPlantilla"].ToString();
                            string _Fecha_Modificacion = _Row["Fecha_Modificacion"].ToString();
                            string _Linea = null;

                            if (File.Exists(_Path + "\\jsons\\Update" + _IdTipoPlantilla + ".txt"))
                            {
                                StreamReader sw = new StreamReader(_Path + "\\Jsons\\Update" + _IdTipoPlantilla + ".txt");
                                _Linea = sw.ReadLine();
                                sw.Close();

                                if (_Linea != null)
                                {
                                    if (_Linea != _Fecha_Modificacion)
                                    {
                                        this.TopMost = false;
                                        this.Enabled = false;
                                        this.Hide();
                                        FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                                        _FileJsonfrm._Form    = this;
                                        _FileJsonfrm._Process = false;
                                        _FileJsonfrm._Update  = true;
                                        _FileJsonfrm._window  = this.Text;
                                        _FileJsonfrm.Show();
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    FillYears(cmbAnio);
                    FillTemplateType(cmbTipo);
                }
                else
                {
                    if (!_Connection)
                    {
                        MessageBox.Show(_Message.Replace("...", ", para crear los archivos base..."), "Creación de Archivos Base", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.btnAgregar.Enabled   = false;
                        this.btnModificar.Enabled = false;
                        this.btnEliminar.Enabled  = false;
                        return;
                    }
                    else
                    {
                        this.TopMost = false;
                        this.Enabled = false;
                        this.Hide();
                        FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                        _FileJsonfrm._Form    = this;
                        _FileJsonfrm._Process = false;
                        _FileJsonfrm._Update  = false;
                        _FileJsonfrm._window  = this.Text;
                        _FileJsonfrm.Show();
                        return;
                    }
                }
                if (File.Exists(_Path + "\\jsons\\Cruces.json"))
                {
                    _Cruces = Assembler.LoadJson <oCruce[]>($"{_Path}\\jsons\\Cruces.json");
                    var _CrucesI = (from x in _Cruces.ToList()
                                    select new
                    {
                        Numero = x.IdCruce,
                        x.Concepto,
                        TipoMov = ""
                    }).ToList();

                    DtCruces.DataSource = ToDataTable(_CrucesI);
                    if (DtCruces.RowCount == 0)
                    {
                        CrucesCLick(-1);
                    }
                    else
                    {
                        CrucesCLick(0);
                    }
                }
                else
                {
                    this.TopMost = false;
                    this.Enabled = false;
                    this.Hide();
                    FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                    _FileJsonfrm._Form    = this;
                    _FileJsonfrm._Process = false;
                    _FileJsonfrm._Update  = false;
                    _FileJsonfrm._window  = this.Text;
                    _FileJsonfrm.Show();
                    return;
                }
            }
            else
            {
                if (!Directory.Exists(_Path + "\\jsons"))
                {
                    Directory.CreateDirectory(_Path + "\\jsons");
                }
                if (!Directory.Exists(_Path + "\\templates"))
                {
                    Directory.CreateDirectory(_Path + "\\templates");
                }

                this.TopMost = false;
                this.Enabled = false;
                this.Hide();
                FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                _FileJsonfrm._Form    = this;
                _FileJsonfrm._Process = false;
                _FileJsonfrm._Update  = false;
                _FileJsonfrm._window  = this.Text;
                _FileJsonfrm.Show();
                return;
            }
        }
Exemplo n.º 4
0
        /// <summary>Función que obtiene los Sub Totales.
        /// <para>Obtiene los Sub Totales en el archivo de Json. Referencia: <see cref="DameColumnasST(string)"/> se agrega la referencia ExcelAddIn.Generales para invocarla.</para>
        /// <seealso cref="DameColumnasST(string)"/>
        /// </summary>
        public static List <oSubtotal> DameColumnasST(string Hoja)
        {
            List <oSubtotal> Subtotales = new List <oSubtotal>();

            string _Path       = ExcelAddIn.Access.Configuration.Path;
            bool   _Connection = new lSerializados().CheckConnection(ExcelAddIn.Access.Configuration.UrlConnection);
            string _Message    = "No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.";

            if (Directory.Exists(_Path + "\\jsons") && Directory.Exists(_Path + "\\templates"))
            {
                if (File.Exists(_Path + "\\jsons\\Indices.json"))
                {
                    if (_Connection)
                    {
                        KeyValuePair <bool, System.Data.DataTable> _TipoPlantilla = new lSerializados().ObtenerUpdate();

                        foreach (DataRow _Row in _TipoPlantilla.Value.Rows)
                        {
                            string _IdTipoPlantilla    = _Row["IdTipoPlantilla"].ToString();
                            string _Fecha_Modificacion = _Row["Fecha_Modificacion"].ToString();
                            string _Linea = null;

                            if (File.Exists(_Path + "\\jsons\\Update" + _IdTipoPlantilla + ".txt"))
                            {
                                StreamReader sw = new StreamReader(_Path + "\\Jsons\\Update" + _IdTipoPlantilla + ".txt");
                                _Linea = sw.ReadLine();
                                sw.Close();

                                if (_Linea != null)
                                {
                                    if (_Linea != _Fecha_Modificacion)
                                    {
                                        FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                                        _FileJsonfrm._Process = true;
                                        _FileJsonfrm._Update  = true;
                                        _FileJsonfrm._window  = "";
                                        _FileJsonfrm.Show();
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (!_Connection)
                    {
                        MessageBox.Show(_Message.Replace("...", ", para crear los archivos base..."), "Creación de Archivos Base", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(null);
                    }
                    else
                    {
                        FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                        _FileJsonfrm._Process = true;
                        _FileJsonfrm._window  = "";
                        _FileJsonfrm.Show();
                    }
                }
            }
            else
            {
                if (!Directory.Exists(_Path + "\\jsons"))
                {
                    Directory.CreateDirectory(_Path + "\\jsons");
                }
                if (!Directory.Exists(_Path + "\\templates"))
                {
                    Directory.CreateDirectory(_Path + "\\templates");
                }
                if (!_Connection)
                {
                    MessageBox.Show(_Message.Replace("...", ", para crear los archivos base..."), "Creación de Archivos Base", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                else
                {
                    FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                    _FileJsonfrm._Process = true;
                    _FileJsonfrm._window  = "";
                    _FileJsonfrm.Show();
                }
            }

            oRootobject _Root = Assembler.LoadJson <oRootobject>($"{_Path}\\jsons\\Indices.json");

            Subtotales = _Root.Subtotales;

            return(Subtotales.Where(x => x.Hoja == Hoja.Trim()).ToList());
        }
Exemplo n.º 5
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            bool   _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);
            string _Message    = "No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.";
            string _Title      = "Conexión de Red";

            if (_Connection)
            {
                int           Row           = DtComprobaciones.CurrentCell.RowIndex;
                int           IDcompro      = Convert.ToInt32(DtComprobaciones.Rows[Row].Cells[0].Value.ToString());
                oComprobacion _Comprobacion = _Comprobaciones.Where(o => o.IdComprobacion == IDcompro).FirstOrDefault();
                DialogResult  dialogo       = MessageBox.Show("Desea eliminar fórmula número " + IDcompro.ToString() + "?",
                                                              "Confirme", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dialogo == DialogResult.Yes)
                {
                    _Message = ((cmbTipo.SelectedIndex == 0) ? "- Debe seleccionar un tipo de plantilla" : "");
                    if (_Message.Length > 0)
                    {
                        MessageBox.Show(_Message, "Información Faltante", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (_Comprobacion.AdmiteCambios == 0)
                    {
                        MessageBox.Show("La fórmula no puede ser eliminada ya que es un cálculo de " + cmbTipo.Text, "Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    DialogResult _response = DialogResult.None;

                    oComprobacion _Template = new oComprobacion()
                    {
                        IdComprobacion  = IDcompro,
                        IdTipoPlantilla = cmbTipo.SelectedIndex,
                        Concepto        = "",
                        Formula         = "",
                        Condicion       = "",
                        Nota            = ""
                    };
                    KeyValuePair <bool, string[]> _result = new lComprobacionesAdmin(_Template, "E").Delete();
                    string _Messages = "";
                    foreach (string _Msg in _result.Value)
                    {
                        _Messages += ((_Messages.Length > 0) ? "\r\n" : "") + _Msg;
                    }
                    if (_result.Key && _response != DialogResult.Yes)
                    {
                        _Messages = "Fórmula eliminada con éxito";
                    }
                    MessageBox.Show(_Messages, (_result.Key) ? "Proceso Existoso" : "Información Faltante", MessageBoxButtons.OK, (_result.Key) ? MessageBoxIcon.Information : MessageBoxIcon.Exclamation);

                    if (_result.Key)
                    {
                        string       _Path      = Configuration.Path;
                        oPlantilla[] _Templates = Assembler.LoadJson <oPlantilla[]>($"{_Path}\\jsons\\Plantillas.json");
                        oPlantilla   _Temp      = _Templates.FirstOrDefault(o => o.IdTipoPlantilla == _Template.IdTipoPlantilla && o.Anio == (int)cmbAnio.SelectedValue);

                        //Libro Actual de Excel.
                        Excel.Worksheet xlSht;
                        Excel.Workbook  wb         = Globals.ThisAddIn.Application.ActiveWorkbook;
                        string[]        Formula    = _Comprobacion.Formula.Split('=');
                        string[]        _celdaBase = Formula[0].Replace("[", "").Replace("]", "").Split(',');
                        string[]        _celdaFin  = Formula[1].Replace("[", "").Replace("]", "").Split(',');
                        Excel.Range     _RangeO;
                        Excel.Range     _RangeR;

                        xlSht = (Excel.Worksheet)wb.Worksheets.get_Item(_celdaBase[0]);
                        for (int a = 1; a < 1000; a++)
                        {
                            _RangeO = (Excel.Range)xlSht.get_Range($"A" + a.ToString());

                            if (_RangeO != null)
                            {
                                if (_RangeO.Value.ToString() == _celdaBase[1])
                                {
                                    _RangeR              = (Excel.Range)xlSht.get_Range($"{Generales.ColumnAdress(Int32.Parse(_celdaBase[2]))}" + a.ToString());
                                    _RangeR.Formula      = "";
                                    _RangeR.Value        = "";
                                    _RangeR.NumberFormat = "@";
                                    _RangeR.Value2       = "";

                                    a = 1001;
                                }
                            }
                        }
                        FileJson(_Temp, cmbTipo.SelectedIndex.ToString());
                        this.Hide();
                    }
                }
            }
            else
            {
                MessageBox.Show(_Message, _Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btguardar_Click(object sender, EventArgs e)
        {
            bool   _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);
            string _Message    = "No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.";
            string _Title      = "Conexión de Red";

            if (_Connection)
            {
                _Message  = (txtConcepto.Text.Trim() == "") ? "- Debe indicar concepto." : "";
                _Message += (txtcelda.Text.Trim() == "") ? ((_Message.Length > 0) ? "\r\n" : "") + "- Debe indicar celda." : "";
                _Message += (txtformula.Text.Trim() == "") ? ((_Message.Length > 0) ? "\r\n" : "") + "- Debe indicar fórmula." : "";
                _Message += (chkCondicionar.Checked && txtCondicion.Text.Trim() == "") ? ((_Message.Length > 0) ? "\r\n" : "") + "- Debe indicar condición." : "";

                if (_Message.Length > 0)
                {
                    MessageBox.Show(_Message, "Información Faltante", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                DialogResult _response = DialogResult.None;
                string       Formulax  = (txtcelda.Text + "=" + txtformula.Text);
                string       condicion = "";

                if (chkCondicionar.Checked)
                {
                    condicion = txtCondicion.Text;
                }


                oComprobacion _Template = new oComprobacion()
                {
                    IdComprobacion  = Convert.ToInt32(txtNro.Text),
                    IdTipoPlantilla = TpPlantilla,//buscar
                    Concepto        = txtConcepto.Text,
                    Formula         = Formulax,
                    Condicion       = condicion,
                    Nota            = txtNota.Text,
                };

                if (accion == "A")
                {
                    KeyValuePair <bool, string[]> _result = new lComprobacionesAdmin(_Template, accion).Add();

                    string _Messages = "";
                    foreach (string _Msg in _result.Value)
                    {
                        _Messages += ((_Messages.Length > 0) ? "\r\n" : "") + _Msg;
                    }
                    if (_result.Key && _response != DialogResult.Yes)
                    {
                        _Messages = "Comprobación agregada con éxito";
                    }
                    MessageBox.Show(_Messages, (_result.Key) ? "Proceso Existoso" : "Información Faltante", MessageBoxButtons.OK, (_result.Key) ? MessageBoxIcon.Information : MessageBoxIcon.Exclamation);
                    if (_result.Key)
                    {
                        this.Hide();
                    }
                }
                else
                if (accion == "M")
                {
                    KeyValuePair <bool, string[]> _result = new lComprobacionesAdmin(_Template, accion).Update();

                    string _Messages = "";
                    foreach (string _Msg in _result.Value)
                    {
                        _Messages += ((_Messages.Length > 0) ? "\r\n" : "") + _Msg;
                    }
                    if (_result.Key && _response != DialogResult.Yes)
                    {
                        _Messages = "Comprobación modificada con éxito";
                    }
                    MessageBox.Show(_Messages, (_result.Key) ? "Proceso Existoso" : "Información Faltante", MessageBoxButtons.OK, (_result.Key) ? MessageBoxIcon.Information : MessageBoxIcon.Exclamation);
                    if (_result.Key)
                    {
                        this.Hide();
                    }
                }
            }
            else
            {
                MessageBox.Show(_Message, _Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 7
0
        private void btnPrellenar_Click(object sender, RibbonControlEventArgs e)
        {
            string _CnStr      = string.Format(Configuration.ConnectionStringPrellenado, Configuration.Server, Configuration.DataBase, Configuration.User, Configuration.Password);
            bool   _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);

            string _RFC  = String.Empty;
            int    _Anio = 0;

            string[] strFileame;
            int      _MaxRow = 0;

            Excel.Workbook  wb = Globals.ThisAddIn.Application.ActiveWorkbook;
            Excel.Worksheet xlSht;

            xlSht   = (Excel.Worksheet)wb.Worksheets.get_Item("Contribuyente");
            _MaxRow = xlSht.UsedRange.Count + 1;


            if (xlSht != null)
            {
                Excel.Range range     = (Excel.Range)xlSht.get_Range("A1:A" + _MaxRow.ToString());
                Excel.Range findindex = range.Find("01A000000", Type.Missing, Excel.XlFindLookIn.xlValues,
                                                   Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows,
                                                   Excel.XlSearchDirection.xlNext, false, Type.Missing, Type.Missing);
                if (findindex != null)
                {
                    range = (Excel.Range)xlSht.Cells[findindex.Row, 3];
                    _RFC  = range.Value;
                }
            }

            strFileame = Globals.ThisAddIn.Application.Name.Split('-');

            DataTable dt = new DataTable();

            dt.Clear();
            dt.Columns.Add("INDICE");
            dt.Columns.Add("SALDO");
            dt.Columns.Add("CUENTAS");

            DataTable dt2 = new DataTable();

            dt2.Clear();
            dt2.Columns.Add("INDICE");
            dt2.Columns.Add("SALDO");
            dt2.Columns.Add("CUENTAS");

            SqlConnection _DbConn = new SqlConnection(_CnStr);

            try
            {
                if (_Connection)
                {
                    if (!String.IsNullOrWhiteSpace(_RFC))
                    {
                        if (strFileame[0].Equals("SIPRED"))
                        {
                            _Anio = Convert.ToInt16(strFileame[1]);
                            _RFC  = _RFC.Replace("_", "");
                        }
                        else
                        {
                            _Anio = Properties.Settings.Default.Anio;
                            _RFC  = _RFC.Replace("_", "");
                        }

                        using (_DbConn)
                        {
                            SqlCommand _SqlComm = new SqlCommand("dbo.SP_DAgrupa_ObtieneSaldoIndice", _DbConn);
                            _SqlComm.Parameters.AddWithValue("@RFC", _RFC);
                            _SqlComm.Parameters.AddWithValue("@Ejercicio", _Anio.ToString());
                            _SqlComm.Parameters.AddWithValue("@Indice", "");

                            _SqlComm.CommandType = CommandType.StoredProcedure;
                            SqlDataAdapter da = new SqlDataAdapter();

                            da.SelectCommand             = _SqlComm;
                            da.SelectCommand.CommandType = CommandType.StoredProcedure;
                            da.Fill(dt);

                            _SqlComm.Parameters.Clear();

                            _SqlComm.Parameters.AddWithValue("@RFC", _RFC);
                            _SqlComm.Parameters.AddWithValue("@Ejercicio", (_Anio - 1).ToString());
                            _SqlComm.Parameters.AddWithValue("@Indice", "");
                            SqlDataAdapter daT2 = new SqlDataAdapter();
                            daT2.SelectCommand             = _SqlComm;
                            daT2.SelectCommand.CommandType = CommandType.StoredProcedure;
                            daT2.Fill(dt2);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Primero debe indicar el RFC del Cliente [Contribuyentes indice 01A000000]", "Falta Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Porfavor verifique que tiene conexión a internet.", "Sin acceso a la red", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (SqlException sqlex)
            {
                MessageBox.Show($"Error en la conexión. {sqlex.Message.ToString()}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error en la conexión. {ex.Message.ToString()}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                _DbConn.Close();

                if (dt.Rows.Count > 0 || dt2.Rows.Count > 0)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    for (int _wCount = 1; _wCount <= wb.Worksheets.Count; _wCount++)
                    {
                        xlSht = wb.Worksheets[_wCount];
                        Generales._Macro(false, xlSht, Configuration.PwsExcel);
                    }

                    //Generales.Proteccion(false);
                    ValidaSaldoIndice(dt, dt2);
                    //Generales.Proteccion(true);

                    for (int _wCount = 1; _wCount <= wb.Worksheets.Count; _wCount++)
                    {
                        xlSht = wb.Worksheets[_wCount];
                        Generales._Macro(true, xlSht, Configuration.PwsExcel);
                    }
                    Cursor.Current = Cursors.Default;
                }
                else
                {
                    MessageBox.Show($"No hay datos para el cliente {_RFC}, periodo {_Anio}.", "Sin Datos", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        private void btguardar_Click(object sender, EventArgs e)
        {
            bool   _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);
            string _Message    = "No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.";
            string _Title      = "Conexión de Red";

            if (_Connection)
            {
                _Message  = (txtConcepto.Text.Trim() == "") ? "- Debe indicar concepto." : "";
                _Message += (txtcelda.Text.Trim() == "") ? ((_Message.Length > 0) ? "\r\n" : "") + "- Debe indicar celda." : "";
                _Message += (txtformula.Text.Trim() == "") ? ((_Message.Length > 0) ? "\r\n" : "") + "- Debe indicar fórmula." : "";
                _Message += (chkCondicionar.Checked && txtCondicion.Text.Trim() == "") ? ((_Message.Length > 0) ? "\r\n" : "") + "- Debe indicar condición." : "";

                if (_Message.Length > 0)
                {
                    MessageBox.Show(_Message, "Información Faltante", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                DialogResult _response = DialogResult.None;
                string       Formulax  = (txtcelda.Text + "=" + txtformula.Text);
                string       condicion = "";

                if (chkCondicionar.Checked)
                {
                    condicion = txtCondicion.Text;
                }


                oComprobacion _Template = new oComprobacion()
                {
                    IdComprobacion  = Convert.ToInt32(txtNro.Text),
                    IdTipoPlantilla = TpPlantilla,//buscar
                    Concepto        = txtConcepto.Text,
                    Formula         = Formulax,
                    Condicion       = condicion,
                    Nota            = txtNota.Text,
                };

                if (accion == "A")
                {
                    KeyValuePair <bool, string[]> _result = new lComprobacionesAdmin(_Template, accion).Add();

                    string _Messages = "";
                    foreach (string _Msg in _result.Value)
                    {
                        _Messages += ((_Messages.Length > 0) ? "\r\n" : "") + _Msg;
                    }
                    if (_result.Key && _response != DialogResult.Yes)
                    {
                        _Messages = "Comprobación agregada con éxito";
                    }
                    MessageBox.Show(_Messages, (_result.Key) ? "Proceso Existoso" : "Información Faltante", MessageBoxButtons.OK, (_result.Key) ? MessageBoxIcon.Information : MessageBoxIcon.Exclamation);
                    //if (_result.Key) this.Hide();
                }
                else
                if (accion == "M")
                {
                    KeyValuePair <bool, string[]> _result = new lComprobacionesAdmin(_Template, accion).Update();

                    string _Messages = "";
                    foreach (string _Msg in _result.Value)
                    {
                        _Messages += ((_Messages.Length > 0) ? "\r\n" : "") + _Msg;
                    }
                    if (_result.Key && _response != DialogResult.Yes)
                    {
                        _Messages = "Comprobación modificada con éxito";
                    }
                    MessageBox.Show(_Messages, (_result.Key) ? "Proceso Existoso" : "Información Faltante", MessageBoxButtons.OK, (_result.Key) ? MessageBoxIcon.Information : MessageBoxIcon.Exclamation);
                    //if (_result.Key) this.Hide();
                }

                string       _Path      = Configuration.Path;
                oPlantilla[] _Templates = Assembler.LoadJson <oPlantilla[]>($"{_Path}\\jsons\\Plantillas.json");
                oPlantilla   _Temp      = _Templates.FirstOrDefault(o => o.IdTipoPlantilla == _Template.IdTipoPlantilla && o.Anio == _iYear);

                if (_oComprobacion != null)
                {
                    //Libro Actual de Excel.
                    Excel.Worksheet xlSht;
                    Excel.Workbook  wb         = Globals.ThisAddIn.Application.ActiveWorkbook;
                    string[]        Formula    = _oComprobacion.Formula.Split('=');
                    string[]        _celdaBase = Formula[0].Replace("[", "").Replace("]", "").Split(',');
                    string[]        _celdaFin  = Formula[1].Replace("[", "").Replace("]", "").Split(',');
                    Excel.Range     _RangeO;
                    Excel.Range     _RangeR;

                    xlSht = (Excel.Worksheet)wb.Worksheets.get_Item(_celdaBase[0]);
                    for (int a = 1; a < 1000; a++)
                    {
                        _RangeO = (Excel.Range)xlSht.get_Range($"A" + a.ToString());

                        if (_RangeO != null)
                        {
                            if (_RangeO.Value.ToString() == _celdaBase[1])
                            {
                                _RangeR              = (Excel.Range)xlSht.get_Range($"{Generales.ColumnAdress(Int32.Parse(_celdaBase[2]))}" + a.ToString());
                                _RangeR.Formula      = "";
                                _RangeR.Value        = "";
                                _RangeR.NumberFormat = "@";
                                _RangeR.Value2       = "";

                                a = 1001;
                            }
                        }
                    }
                }

                _Form.Close();
                FileJson(_Temp, TpPlantilla.ToString());
                _Form.Show();
            }
            else
            {
                MessageBox.Show(_Message, _Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 9
0
        private void btnGenerar_Click(object sender, EventArgs e)
        {
            List <string> _Messages = new List <string>();

            bool _Key        = true;
            bool _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);

            this.pgbFile.Visible = true;
            int progress = 0;

            progress += 10;

            if (!_Connection)
            {
                for (int x = 10; x <= 100; x++)
                {
                    pgbFile.Value        = 100 - x;
                    this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "%";
                    System.Threading.Thread.Sleep(1500);
                    x += 10;
                }
                MessageBox.Show("No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.", "Conexión de Red", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
            else
            {
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Tipos de Plantillas]"));
                //System.Threading.Thread.Sleep(100);
                KeyValuePair <bool, string[]> _TiposPlantillas = new lSerializados().ObtenerTiposPlantillas();
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Cruces]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Cruces = new lSerializados().ObtenerCruces();
                progress     += 20;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Plantillas]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Plantillas = new lSerializados().ObtenerPlantillas();
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Comprobaciones]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Comprobaciones = new lSerializados().ObtenerComprobaciones();
                progress     += 20;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Validación Cruces]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Validaciones = new lSerializados().ObtenerValidacionCruces();
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Indices]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Indices = new lSerializados().ObtenerIndices();
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "%"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Masiva = new lSerializados().ObtenerConversionMasiva();
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "%"));
                //System.Threading.Thread.Sleep(1000);

                _Key = (!_TiposPlantillas.Key || !_Cruces.Key || !_Plantillas.Key || !_Comprobaciones.Key || !_Validaciones.Key || !_Indices.Key || !_Masiva.Key);
                _Messages.AddRange(_TiposPlantillas.Value);
                _Messages.AddRange(_Cruces.Value);
                _Messages.AddRange(_Plantillas.Value);
                _Messages.AddRange(_Comprobaciones.Value);
                _Messages.AddRange(_Validaciones.Value);
                _Messages.AddRange(_Indices.Value);
                _Messages.AddRange(_Masiva.Value);
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Proceso Finalizado]"));
                //System.Threading.Thread.Sleep(1000);

                string _Message = "Los Archivos fueron creados con éxito. Vuelva a cargar la pantalla de [" + _window + "]. ";
                if (_Update)
                {
                    _Message = "Los Archivos fueron actualizados con éxito. Vuelva a cargar la pantalla de [" + _window + "]. ";
                }
                if (_Process)
                {
                    _Message = "Los Archivos fueron creados con éxito. Click en el botón de Ok para continuar con el proceso.";

                    if (_Update)
                    {
                        _Message = "Los Archivos fueron actualizados con éxito. Click en el botón de Ok para continuar con el proceso.";
                    }
                }

                KeyValuePair <bool, System.Data.DataTable> _TipoPlantilla = new lSerializados().ObtenerUpdate();
                String _Path = Configuration.Path;

                foreach (DataRow _Row in _TipoPlantilla.Value.Rows)
                {
                    string _IdTipoPlantilla    = _Row["IdTipoPlantilla"].ToString();
                    string _Fecha_Modificacion = _Row["Fecha_Modificacion"].ToString();

                    if (File.Exists(_Path + "\\jsons\\Update" + _IdTipoPlantilla + ".txt"))
                    {
                        File.Delete(_Path + "\\jsons\\Update" + _IdTipoPlantilla + ".txt");
                    }
                    StreamWriter sw = new StreamWriter(_Path + "\\Jsons\\Update" + _IdTipoPlantilla + ".txt");
                    sw.WriteLine(_Fecha_Modificacion);
                    sw.Close();
                }


                MessageBox.Show(_Message, "Archivos Base", MessageBoxButtons.OK, MessageBoxIcon.Information);

                if (!_Process)
                {
                    _Form.Close();
                }
                this.Close();
            }
        }
Exemplo n.º 10
0
        private void frmCarga_Load(object sender, EventArgs e)
        {
            string _Path       = Configuration.Path;
            bool   _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);
            string _Message    = "No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.";

            this._ProcessJson = false;
            this.Visible      = true;

            if (Directory.Exists(_Path + "\\jsons") && Directory.Exists(_Path + "\\templates"))
            {
                if (File.Exists(_Path + "\\jsons\\TiposPlantillas.json"))
                {
                    if (_Connection)
                    {
                        KeyValuePair <bool, System.Data.DataTable> _TipoPlantilla = new lSerializados().ObtenerUpdate();

                        foreach (DataRow _Row in _TipoPlantilla.Value.Rows)
                        {
                            string _IdTipoPlantilla    = _Row["IdTipoPlantilla"].ToString();
                            string _Fecha_Modificacion = _Row["Fecha_Modificacion"].ToString();
                            string _Linea = null;

                            if (File.Exists(_Path + "\\jsons\\Update" + _IdTipoPlantilla + ".txt"))
                            {
                                StreamReader sw = new StreamReader(_Path + "\\Jsons\\Update" + _IdTipoPlantilla + ".txt");
                                _Linea = sw.ReadLine();
                                sw.Close();

                                if (_Linea != null)
                                {
                                    if (_Linea != _Fecha_Modificacion)
                                    {
                                        this.TopMost = false;
                                        this.Enabled = false;
                                        this.Hide();
                                        FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                                        _FileJsonfrm._Form    = this;
                                        _FileJsonfrm._Process = false;
                                        _FileJsonfrm._Update  = true;
                                        _FileJsonfrm._window  = this.Text;
                                        _FileJsonfrm.Show();
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (!_Connection)
                    {
                        MessageBox.Show(_Message.Replace("...", ", para crear los archivos base..."), "Creación de Archivos Base", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.btnAccept.Enabled = false;
                        return;
                    }
                    else
                    {
                        this._ProcessJson = true;
                        this.TopMost      = false;
                        this.Enabled      = false;
                        this.Hide();
                        FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                        _FileJsonfrm._Form    = this;
                        _FileJsonfrm._Process = false;
                        _FileJsonfrm._Update  = false;
                        _FileJsonfrm._window  = this.Text;
                        _FileJsonfrm.Show();
                        return;
                    }
                }
            }
            else
            {
                if (!Directory.Exists(_Path + "\\jsons"))
                {
                    Directory.CreateDirectory(_Path + "\\jsons");
                }
                if (!Directory.Exists(_Path + "\\templates"))
                {
                    Directory.CreateDirectory(_Path + "\\templates");
                }

                this._ProcessJson = true;
                this.TopMost      = false;
                this.Enabled      = false;
                this.Hide();
                FileJsonTemplate _FileJsonfrm = new FileJsonTemplate();
                _FileJsonfrm._Form    = this;
                _FileJsonfrm._Process = false;
                _FileJsonfrm._Update  = false;
                _FileJsonfrm._window  = this.Text;
                _FileJsonfrm.Show();
                return;
            }

            FileInfo _Excel = new FileInfo(Globals.ThisAddIn.Application.ActiveWorkbook.FullName);

            if (_Excel.Extension != ".xlsm")
            {
                MessageBox.Show("Archivo no válido, favor de generar el archivo mediante el AddIn D.SAT", "Información Incorrecta", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                return;
            }

            QuitarFormulas();
        }