private void tsmEliminar_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "pa_EliminarCliente_del " + grdDatos.SelectedCells[0].Value.ToString(); cmd.CommandType = CommandType.Text; DataSet ds; ds = Conectar.Listar(Clases.clsBD.BD, cmd); if (ds.Tables[0].Rows.Count > 0) { if ((int)ds.Tables[0].Rows[0]["Resultado"] == 0) { classFuncionesGenerales.mensajes.MensajeAdvertencia("Cliente se dejo Inactivo, Debe ingresar una observación porque se dejo inactivo"); frmObservacionCliente frm1 = new frmObservacionCliente(grdDatos.SelectedCells[0].Value.ToString(), ds.Tables[0].Rows[0]["FechaInicio"].ToString()); frm1.ShowDialog(this); } else { classFuncionesGenerales.mensajes.MensajeAdvertencia(ds.Tables[0].Rows[0]["Mensaje"].ToString()); } } Listar_Cliente(); }
private void Grabar() { Boolean bolResult; bolResult = false; //if (Convert.ToDateTime(cbx_id_periodo.Text.ToString()) > DateTime.Now.Date) //{ // Cursor = Cursors.Default; // MessageBox.Show("FEcha inicio control es mayor que la fecha actual", ControlDosimetro.Properties.Resources.msgCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} // if (MessageBox.Show("Desea grabar la información", "mensaje", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) // { if (btn_Grabar.Text == "Modificar") { ClaseComun.Modificar(Clases.clsBD.BD, tbl_cliente, ref bolResult); if (bolResult == true) { if (cbx_id_estado.SelectedValue.ToString() == "0") { if (lbl_Estado_mod.Text != cbx_id_estado.Text) { SqlCommand cmd1 = new SqlCommand(); cmd1.CommandText = "pa_ClienteHistorial_upd " + txt_id_cliente.Text + ",'" + dtp_FechaInicio.Value.ToShortDateString().Replace("-", "/") + "'"; cmd1.CommandType = CommandType.Text; DataSet ds = Conectar.Listar(Clases.clsBD.BD, cmd1); if ((int)ds.Tables[0].Rows[0]["Resultado"] == 0) { MessageBox.Show(ds.Tables[0].Rows[0]["Mensaje"].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } MessageBox.Show("Dato modificado,Debe ingresar una observación porque se dejo inactivo"); frmObservacionCliente frm1 = new frmObservacionCliente(txt_id_cliente.Text, dtp_FechaInicio.Text); frm1.ShowDialog(this); this.Close(); } else { SqlCommand cmd1 = new SqlCommand(); cmd1.CommandText = "pa_ClienteHistorial_upd " + txt_id_cliente.Text + ",'" + dtp_FechaInicio.Value.ToShortDateString().Replace("-", "/") + "'"; cmd1.CommandType = CommandType.Text; DataSet ds = Conectar.Listar(Clases.clsBD.BD, cmd1); if ((int)ds.Tables[0].Rows[0]["Resultado"] == 0) { MessageBox.Show(ds.Tables[0].Rows[0]["Mensaje"].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if ((int)ds.Tables[0].Rows[0]["Resultado"] == 1) { MessageBox.Show(ds.Tables[0].Rows[0]["Mensaje"].ToString(), "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { SqlCommand cmd1 = new SqlCommand(); cmd1.CommandText = "pa_ClienteHistorial_upd " + txt_id_cliente.Text + ",'" + dtp_FechaInicio.Value.ToShortDateString().Replace("-", "/") + "'"; cmd1.CommandType = CommandType.Text; DataSet ds = Conectar.Listar(Clases.clsBD.BD, cmd1); if ((int)ds.Tables[0].Rows[0]["Resultado"] == 0) { MessageBox.Show(ds.Tables[0].Rows[0]["Mensaje"].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if ((int)ds.Tables[0].Rows[0]["Resultado"] == 1) { MessageBox.Show(ds.Tables[0].Rows[0]["Mensaje"].ToString(), "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information); } } this.Close(); } } else { if (valida_cliente(Convert.ToInt64(txt_id_cliente.Text)) == false) { ClaseComun.Insertar(Clases.clsBD.BD, tbl_cliente, ref bolResult); if (bolResult == true) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "pa_Sucursal_ins '" + txt_run.Text + "','" + txt_direccion.Text + "'," + cbx_id_region.SelectedValue + "," + cbx_id_provincia.SelectedValue + "," + cbx_id_comuna.SelectedValue + ",'" + txt_telefono.Text + "',1,1," + txt_id_cliente.Text + ",'" + txt_Email.Text + "','" + txt_Razon_Social.Text + "'"; cmd.CommandType = CommandType.Text; Conectar.AgregarModificarEliminar(Clases.clsBD.BD, cmd); SqlCommand cmd1 = new SqlCommand(); cmd1.CommandText = "pa_ClienteHistorial_ins " + txt_id_cliente.Text; cmd1.CommandType = CommandType.Text; Conectar.AgregarModificarEliminar(Clases.clsBD.BD, cmd1); SqlCommand cmdArchivo = new SqlCommand(); //SqlCommand cmdcombo = new SqlCommand(); DataSet dtArchivo; cmdArchivo.CommandText = "" + "SELECT Id_DetParametro,Glosa,orden FROM conf_detparametro where id_estado=1 and Id_Parametro=6 order by orden "; cmdArchivo.CommandType = CommandType.Text; dtArchivo = Conectar.Listar(Clases.clsBD.BD, cmdArchivo); DataSet dtformato; cmdArchivo.CommandText = "" + "SELECT Id_DetParametro,Glosa,orden FROM conf_detparametro where id_estado=1 and Id_Parametro=5 order by orden "; cmdArchivo.CommandType = CommandType.Text; dtformato = Conectar.Listar(Clases.clsBD.BD, cmdArchivo); string targetPath = dtArchivo.Tables[0].Rows[0]["Glosa"].ToString() + "Cliente " + lbl_id_cliente.Text; MessageBox.Show("Dato Guardado "); //y se va a generar documento de Certificado //if (!System.IO.Directory.Exists(targetPath)) //{ // System.IO.Directory.CreateDirectory(targetPath); //} //String strArchivo = "C://Formato//" + "CERT CON FIRMA INCLUIDA.docx";//dtformato.Tables[0].Rows[0]["Glosa"].ToString() + "CERT CON FIRMA INCLUIDA.docx"; //String strArchivoCopiar = "C://Formato//" + "Certificado Cliente" + lbl_id_cliente.Text + ".docx"; //#region Update Document Bookmarks Openxml //String strcampoMarcador = "empresa"; //using (WordprocessingDocument doc = WordprocessingDocument.Open(strArchivoCopiar, true)) //{ // string strSemetre1 = ""; // int intMes = Convert.ToInt32(dtp_FechaInicio.MaxDate.Month) / 3; // if (intMes >= 1 && intMes <= 3) // strSemetre1 = "primer"; // if (intMes >= 4 && intMes <= 6) // strSemetre1 = "segundo"; // if (intMes >= 7 && intMes <= 9) // strSemetre1 = "tercer"; // if (intMes >= 10 && intMes <= 12) // strSemetre1 = "cuarto"; // strcampoMarcador = "Ciudad"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), cbx_id_provincia.Text); // strcampoMarcador = "Direccion"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), txt_direccion.Text); // strcampoMarcador = "Rut"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), txt_run.Text); // strcampoMarcador = "empresa"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), txt_Razon_Social.Text); // strcampoMarcador = "comuna"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), cbx_id_comuna.Text); // strcampoMarcador = "anno"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), dtp_FechaInicio.MaxDate.Year.ToString()); // strcampoMarcador = "trimestre"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), strSemetre1); //} //#endregion //this.Close(); } else { MessageBox.Show("El número de cliente ya existe, verificar"); } } else { if (valida_cliente_activo(Convert.ToInt64(txt_id_cliente.Text)) == true) { MessageBox.Show("El número de cliente ya existe, verificar"); } else { ClaseComun.Modificar(Clases.clsBD.BD, tbl_cliente, ref bolResult); if (bolResult == true) { MessageBox.Show("Dato Guardado"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "pa_Sucursal_ins '" + txt_run.Text + "','" + txt_direccion.Text + "'," + cbx_id_region.SelectedValue + "," + cbx_id_provincia.SelectedValue + "," + cbx_id_comuna.SelectedValue + ",'" + txt_telefono.Text + "',1,1," + txt_id_cliente.Text + ",'" + txt_Email.Text + "','" + txt_Razon_Social.Text + "'"; cmd.CommandType = CommandType.Text; Conectar.AgregarModificarEliminar(Clases.clsBD.BD, cmd); SqlCommand cmd1 = new SqlCommand(); cmd1.CommandText = "pa_ClienteHistorial_ins " + txt_id_cliente.Text; cmd1.CommandType = CommandType.Text; Conectar.AgregarModificarEliminar(Clases.clsBD.BD, cmd1); SqlCommand cmdArchivo = new SqlCommand(); //SqlCommand cmdcombo = new SqlCommand(); DataSet dtArchivo; cmdArchivo.CommandText = "" + "SELECT Id_DetParametro,Glosa,orden FROM conf_detparametro where id_estado=1 and Id_Parametro=6 order by orden "; cmdArchivo.CommandType = CommandType.Text; dtArchivo = Conectar.Listar(Clases.clsBD.BD, cmdArchivo); DataSet dtformato; cmdArchivo.CommandText = "" + "SELECT Id_DetParametro,Glosa,orden FROM conf_detparametro where id_estado=1 and Id_Parametro=5 order by orden "; cmdArchivo.CommandType = CommandType.Text; dtformato = Conectar.Listar(Clases.clsBD.BD, cmdArchivo); //string targetPath = dtArchivo.Tables[0].Rows[0]["Glosa"].ToString() + "Cliente " + lbl_id_cliente.Text; //if (!System.IO.Directory.Exists(targetPath)) //{ // System.IO.Directory.CreateDirectory(targetPath); //} //string strArchivo = dtformato.Tables[0].Rows[0]["Glosa"].ToString() + "CERT CON FIRMA INCLUIDA.docx"; //String strArchivoCopiar = targetPath + "Certificado Cliente" + lbl_id_cliente.Text + ".docx"; //#region Update Document Bookmarks Openxml //String strcampoMarcador = "empresa"; //using (WordprocessingDocument doc = WordprocessingDocument.Open(strArchivoCopiar, true)) //{ // string strSemetre1 = ""; // int intMes = Convert.ToInt32(dtp_FechaInicio.MaxDate.Month) / 3; // if (intMes >= 1 && intMes <= 3) // strSemetre1 = "primer"; // if (intMes >= 4 && intMes <= 6) // strSemetre1 = "segundo"; // if (intMes >= 7 && intMes <= 9) // strSemetre1 = "tercer"; // if (intMes >= 10 && intMes <= 12) // strSemetre1 = "cuarto"; // strcampoMarcador = "Ciudad"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), cbx_id_provincia.Text); // strcampoMarcador = "Direccion"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), txt_direccion.Text); // strcampoMarcador = "Rut"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), txt_run.Text); // strcampoMarcador = "empresa"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), txt_Razon_Social.Text); // strcampoMarcador = "comuna"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), cbx_id_comuna.Text); // strcampoMarcador = "anno"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), dtp_FechaInicio.MaxDate.Year.ToString()); // strcampoMarcador = "trimestre"; // BookmarkReplacer.ReplaceBookmarkText(doc, strcampoMarcador.ToString(), strSemetre1); //} //#endregion //this.Close(); } } } } // } Cursor = Cursors.Default; }