private void btnCargar_Click(object sender, EventArgs e) { string _Message = (cmbTipoPlantilla.SelectedIndex == 0) ? "- Debe seleccionar un tipo." : ""; _Message += (cmbAnio.SelectedIndex == 0) ? ((_Message.Length > 0) ? "\r\n" : "") + "- Debe seleccionar un año." : ""; _Message += (txtPlantilla.Text == "") ? ((_Message.Length > 0) ? "\r\n" : "") + "- Debe seleccionar un archivo." : ""; if (_Message.Length > 0) { MessageBox.Show(_Message, "Información Faltante", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } oPlantilla[] _Templates = Assembler.LoadJson <oPlantilla[]>($"{Configuration.Path}\\jsons\\Plantillas.json"); oPlantilla _Template = new oPlantilla("app_sipred") { Anio = (int)cmbAnio.SelectedValue, IdTipoPlantilla = (int)cmbTipoPlantilla.SelectedValue, Nombre = new FileInfo(txtPlantilla.Text).Name, Plantilla = File.ReadAllBytes(txtPlantilla.Text) }; DialogResult _response = DialogResult.None; if (_Templates.Where(o => o.IdTipoPlantilla == _Template.IdTipoPlantilla && o.Anio == _Template.Anio).Count() > 0) { _response = MessageBox.Show($"¿Desea reemplazar la plantilla para {((oTipoPlantilla)cmbTipoPlantilla.SelectedItem).FullName} y {cmbAnio.SelectedValue.ToString()}?", "Plantilla Existente", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (_response == DialogResult.No) { btnCancelar_Click(btnCancelar, null); return; } } KeyValuePair <bool, string[]> _result = new lPlantilla(_Template).Add(); string _Messages = ""; foreach (string _Msg in _result.Value) { _Messages += ((_Messages.Length > 0) ? "\r\n" : "") + _Msg; } if (_result.Key && _response != DialogResult.Yes) { _Messages = "La plantilla fue reemplazada con éxito"; } MessageBox.Show(_Messages, (_result.Key) ? "Proceso Existoso" : "Información Faltante", MessageBoxButtons.OK, (_result.Key) ? MessageBoxIcon.Information : MessageBoxIcon.Exclamation); if (_result.Key) { btnCancelar_Click(btnCancelar, null); } }
protected void GenerarArchivo(oPlantilla _Template, string _DestinationPath, string _Tipo) { string _Path = Configuration.Path; // el nombre de una Key debe incluir un root valido. const string userRoot = "HKEY_CURRENT_USER"; const string subkey = "Software\\Microsoft\\Office\\Excel\\Addins\\SAT.Dictamenes.SIPRED.Client"; const string keyName = userRoot + "\\" + subkey; object addInName = "SAT.Dictamenes.SIPRED.Client"; File.Copy($"{_Path}\\templates\\{_Template.Nombre}", _DestinationPath); Registry.SetValue(keyName, "LoadBehavior", 0); Globals.ThisAddIn.Application.COMAddIns.Item(ref addInName).Connect = false; Globals.ThisAddIn.Application.Visible = true; try { Globals.ThisAddIn.Application.Workbooks.Open(_DestinationPath); } catch (Exception ex) { MessageBox.Show($"Error al abrir el archivo [{_DestinationPath}]: {ex.Message.ToString()}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Libro Actual de Excel. Excel.Worksheet xlSht; Excel.Workbook wb = Globals.ThisAddIn.Application.ActiveWorkbook; int count = wb.Worksheets.Count; xlSht = (Excel.Worksheet)wb.Worksheets.Add(Type.Missing, wb.Worksheets[count], Type.Missing, Type.Missing); xlSht.Name = "SIPRED"; wb.Save(); this.TopMost = false; this.Enabled = false; this.Hide(); FormulasComprobaciones _Formulas = new FormulasComprobaciones(); _Formulas._Form = this; _Formulas._Template = _Template; _Formulas._Tipo = _Tipo; _Formulas._formulas = true; _Formulas._Open = false; _Formulas.ShowDialog(); }
private void FileJson(oPlantilla _Template, string _Tipo) { this.TopMost = false; //this.Enabled = false; //this.Hide(); FileJsonTemplate _FileJsonfrm = new FileJsonTemplate(); _FileJsonfrm._Form = this; _FileJsonfrm._Process = true; _FileJsonfrm._Update = true; _FileJsonfrm._Automatic = true; _FileJsonfrm._Template = _Template; _FileJsonfrm._Tipo = _Tipo; _FileJsonfrm._window = this.Text; _FileJsonfrm.Show(); this.TopMost = true; this.Close(); return; }
/// <summary>Función para generar el Archivo Excel según el Tipo de Plantilla. /// <para>Ejecuta la creación del Archivo Excel para el Tipo de Plantilla. Referencia: <see cref="lPlantilla(oPlantilla)"/> se agrega la referencia ExcelAddIn.Logic para invocarla.</para> /// <seealso cref="lPlantilla(oPlantilla)"/> /// </summary> public lPlantilla(oPlantilla _Template) : base(_Template) { Template = _Template; if (Template.IdTipoPlantilla == 0) { _Messages.Add("Debe seleccionar un tipo."); } if (Template.Anio == 0) { _Messages.Add("Debe seleccionar un año."); } if (string.IsNullOrEmpty(Template.Nombre) || string.IsNullOrWhiteSpace(Template.Nombre)) { _Messages.Add("Debe seleccionar un archivo."); } if (Template.Nombre.Length > 0 && Template.Plantilla.Length == 0) { _Messages.Add("Debe seleccionar un archivo."); } }
private void btnCrear_Click(object sender, EventArgs e) { string _Path = Configuration.Path; oPlantilla[] _Templates = Assembler.LoadJson <oPlantilla[]>($"{_Path}\\jsons\\Plantillas.json"); int _IdTemplateType = (int)cmbTipo.SelectedValue, _Year = (int)cmbAnio.SelectedValue; if (_IdTemplateType == 0) { MessageBox.Show("Favor de seleccionar un Tipo de Plantilla.", "Tipo", MessageBoxButtons.OK, MessageBoxIcon.Error); this.cmbTipo.Focus(); return; } if (_Year == 0) { MessageBox.Show("Favor de seleccionar el Año a Aplicar al Tipo de Plantilla.", "Año", MessageBoxButtons.OK, MessageBoxIcon.Error); this.cmbAnio.Focus(); return; } oPlantilla _Template = _Templates.FirstOrDefault(o => o.IdTipoPlantilla == _IdTemplateType && o.Anio == _Year); if (_Template == null) { MessageBox.Show("No existe una plantilla para el tipo seleccionado, favor de seleccionar otro tipo o contactar al administrador.", "Información Incorrecta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } fbdTemplate.ShowDialog(); string _DestinationPath = fbdTemplate.SelectedPath; if (_DestinationPath == "") { MessageBox.Show("Debe especificar un ruta", "Ruta Invalida", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string _newTemplate = $"{_DestinationPath}\\{((oTipoPlantilla)cmbTipo.SelectedItem).Clave}-{cmbAnio.SelectedValue.ToString()}-{DateTime.Now.ToString("ddMMyyyyHHmmss")}_{_IdTemplateType}_{_Year}.xlsm"; GenerarArchivo(_Template, _newTemplate, ((oTipoPlantilla)cmbTipo.SelectedItem).Clave); //this.Close(); }
/// <summary> /// Carga el Grid con los cruces del json realizando el filtro por tipo y año validando contra plantillas.json /// </summary> private void CargaDTCruces() { string _Path = Configuration.Path; bool bOk = true; oPlantilla[] _Templates = Assembler.LoadJson <oPlantilla[]>($"{_Path}\\jsons\\Plantillas.json"); int _IdTemplateType = (int)cmbTipo.SelectedValue, _Year = (int)cmbAnio.SelectedValue; if (_IdTemplateType == 0) { MessageBox.Show("Favor de seleccionar un Tipo de Plantilla.", "Tipo", MessageBoxButtons.OK, MessageBoxIcon.Error); this.cmbTipo.Focus(); bOk = false; } if (_Year == 0 && bOk) { MessageBox.Show("Favor de seleccionar el Año a Aplicar al Tipo de Plantilla.", "Año", MessageBoxButtons.OK, MessageBoxIcon.Error); this.cmbAnio.Focus(); bOk = false; } oPlantilla _Template = _Templates.FirstOrDefault(o => o.IdTipoPlantilla == _IdTemplateType && o.Anio == _Year); if (_Template == null && bOk) { MessageBox.Show("No existe una plantilla para el tipo seleccionado, favor de seleccionar otro tipo o contactar al administrador.", "Información Incorrecta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); bOk = false; } if (bOk) { var _CrucesI = (from x in _Cruces.ToList() where x.IdTipoPlantilla == _IdTemplateType select new { Numero = x.IdCruce, x.Concepto, TipoMov = "" }).ToList(); if (txtbuscar.Text.Trim() != "") { var _Crucesx = _Cruces.Where(p => p.Concepto.ToUpper().Contains(txtbuscar.Text)).ToList(); _CrucesI = (from x in _Crucesx.ToList() where x.IdTipoPlantilla == _IdTemplateType select new { Numero = x.IdCruce, x.Concepto, TipoMov = "" }).ToList(); } DtCruces.DataSource = ToDataTable(_CrucesI); } else { DtCruces.DataSource = null; } if (DtCruces.RowCount == 0) { CrucesCLick(-1); } else { CrucesCLick(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(); } 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); } }
public aPlantilla(oPlantilla _Template) : base() { }