private void updateMateriales(string c_clave, float cant, float m_lineales, float m_cuadrados, string acabado = "") { cotizaciones_local cotizaciones = new cotizaciones_local(); try { if (acabado != "") { var materiales = (from x in cotizaciones.materiales_modulos where x.clave == c_clave && x.acabado == acabado select x).SingleOrDefault(); if (materiales != null) { materiales.cantidad = materiales.cantidad + cant; materiales.metros_lineales = materiales.metros_lineales + m_lineales; materiales.metros_cuadrados = materiales.metros_cuadrados + m_cuadrados; } cotizaciones.SaveChanges(); } else { var materiales = (from x in cotizaciones.materiales_modulos where x.clave == c_clave select x).SingleOrDefault(); if (materiales != null) { materiales.cantidad = materiales.cantidad + cant; materiales.metros_lineales = materiales.metros_lineales + m_lineales; materiales.metros_cuadrados = materiales.metros_cuadrados + m_cuadrados; } cotizaciones.SaveChanges(); } } catch (Exception err) { constants.errorLog(err.ToString()); } }
//Set Data to Report private void setData(int id, byte[] pic, string descripcion, string observaciones, string ubicacion, string medidas, string vista, string apertura, string aluminio, string cristal, string otros, string herrajes, int cantidad) { try { cotizaciones_local data = new cotizaciones_local(); produccion_t p = new produccion_t() { id = id, pic = pic, ubicacion = ubicacion, descripcion = descripcion, observaciones = observaciones, medidas = medidas, vista = vista, apertura = apertura, aluminio = aluminio, cristal = cristal, otros = otros, herrajes = herrajes, cantidad = cantidad }; data.produccion_t.Add(p); data.SaveChanges(); } catch (Exception err) { constants.errorLog(err.ToString()); } }
private void insertarCortes(string clave, string articulo, int modulo_id, string partida, float longitud_corte, float tramo_perfil, string acabado, float cantidad) { cotizaciones_local cotizaciones = new cotizaciones_local(); try { var p = new corte() { clave = clave, articulo = articulo, modulo_id = modulo_id, partida = partida, longitud_corte = longitud_corte, tramo_perfil = tramo_perfil, acabado = acabado, cantidad = cantidad }; cotizaciones.cortes.Add(p); cotizaciones.SaveChanges(); } catch (Exception err) { constants.errorLog(err.ToString()); } }
private void insertarMateriales(int concepto, string clave, string articulo, float cant, float m_lineales, float m_cuadrados, string acabado = "", float largo_perfil = 0) { cotizaciones_local cotizaciones = new cotizaciones_local(); try { var p = new materiales_modulos() { concepto = concepto, clave = clave, articulo = articulo, cantidad = cant, metros_lineales = m_lineales, metros_cuadrados = m_cuadrados, acabado = acabado, largo_perfil = largo_perfil }; cotizaciones.materiales_modulos.Add(p); cotizaciones.SaveChanges(); } catch (Exception err) { constants.errorLog(err.ToString()); } }
private void button3_Click(object sender, EventArgs e) { cotizaciones_local cotizaciones = new cotizaciones_local(); var modulos = (from x in cotizaciones.modulos_cotizaciones where x.id == id select x).SingleOrDefault(); if (modulos != null) { Bitmap bm = new Bitmap(tableLayoutPanel1.Width, tableLayoutPanel1.Height); tableLayoutPanel1.DrawToBitmap(bm, new Rectangle(0, 0, tableLayoutPanel1.Width, tableLayoutPanel1.Height)); Bitmap gm_2 = new Bitmap(bm, 120, 105); modulos.pic = constants.imageToByte(gm_2); modulos.dir = 3; bm = null; gm_2 = null; modulos.new_desing = setNewDesing(); cotizaciones.SaveChanges(); if (Application.OpenForms["articulos_cotizacion"] != null) { ((articulos_cotizacion)Application.OpenForms["articulos_cotizacion"]).reloadModulos(); } if (Application.OpenForms["edit_expresss"] != null) { ((edit_expresss)Application.OpenForms["edit_expresss"]).reloadALL(); } this.Close(); } }
//cambiar imagen private void button2_Click(object sender, EventArgs e) { if (tableLayoutPanel1.Controls.Count > 0 || pictureBox1.Image != null) { cotizaciones_local cotizaciones = new cotizaciones_local(); var data = (from x in cotizaciones.modulos_cotizaciones where x.id == id select x).SingleOrDefault(); if (data != null) { if (tableLayoutPanel1.Controls.Count > 0) { Bitmap bm = new Bitmap(tableLayoutPanel1.Width, tableLayoutPanel1.Height); tableLayoutPanel1.DrawToBitmap(bm, new Rectangle(0, 0, tableLayoutPanel1.Width, tableLayoutPanel1.Height)); Bitmap gm_2 = new Bitmap(bm, 120, 105); data.pic = constants.imageToByte(gm_2); data.dir = 3; data.new_desing = desing > 0 ? desing.ToString() : ""; cotizaciones.SaveChanges(); bm = null; gm_2 = null; } else if (pictureBox1.Image != null) { data.pic = constants.imageToByte(pictureBox1.Image); data.dir = 3; cotizaciones.SaveChanges(); } if (Application.OpenForms["articulos_cotizacion"] != null) { ((articulos_cotizacion)Application.OpenForms["articulos_cotizacion"]).reloadModulos(); } if (Application.OpenForms["edit_expresss"] != null) { ((edit_expresss)Application.OpenForms["edit_expresss"]).reloadALL(); } this.Close(); } } else { MessageBox.Show("[Error] no se ha seleccionado un esquema o imagen.", constants.msg_box_caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void borrarImagenPredeterminada(int perso_id) { cotizaciones_local cotizaciones = new cotizaciones_local(); var concepto = (from x in cotizaciones.modulos_cotizaciones where x.id == perso_id select x).SingleOrDefault(); if (concepto != null) { concepto.pic = null; } cotizaciones.SaveChanges(); }
private void setFactor(cotizaciones_local cotizaciones) { var desglose = from x in cotizaciones.materiales_modulos select x; foreach (var x in desglose) { x.cantidad = x.cantidad * factor; x.metros_lineales = x.metros_lineales * factor; x.metros_cuadrados = x.metros_cuadrados * factor; } cotizaciones.SaveChanges(); }
//Unificar Conceptos private void unificarAConceptosToolStripMenuItem_Click(object sender, EventArgs e) { cotizaciones_local cotizaciones = new cotizaciones_local(); try { var modulo_p = new modulos_cotizaciones { folio = 00000, modulo_id = -1, descripcion = "", mano_obra = 0, dimensiones = "", largo = 0, alto = 0, acabado_perfil = "", claves_cristales = "", cantidad = 1, flete = 0, desperdicio = 0, utilidad = 0, articulo = "", linea = "", diseño = "", clave = "md", total = 0, claves_otros = "", claves_herrajes = "", ubicacion = "", claves_perfiles = "", pic = constants.imageToByte(Properties.Resources.new_concepto), merge_id = -1, concept_id = 0, sub_folio = constants.sub_folio, dir = 0, news = "", new_desing = "", orden = 0 }; cotizaciones.modulos_cotizaciones.Add(modulo_p); cotizaciones.SaveChanges(); ((Form1)Application.OpenForms["Form1"]).countCotizacionesArticulo(); ((Form1)Application.OpenForms["Form1"]).loadCountArticulos(); cargarModulosCotizados(); } catch (Exception err) { constants.errorLog(err.ToString()); MessageBox.Show("[Error] <?>.", constants.msg_box_caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void setNewDir(int id, int dir) { cotizaciones_local cotizacion = new cotizaciones_local(); var modulo = (from x in cotizacion.modulos_cotizaciones where x.id == id select x).SingleOrDefault(); if (modulo != null) { modulo.dir = dir; } cotizacion.SaveChanges(); constants.updateModuloPersonalizado(perso_id); constants.getMargedItems(datagridviewNE1, perso_id); }
private void deleteCopy(int id) { cotizaciones_local cotizaciones = new cotizaciones_local(); var copy = (from x in cotizaciones.copyboxes where x.id == id select x).SingleOrDefault(); if (copy != null) { cotizaciones.copyboxes.Remove(copy); cotizaciones.SaveChanges(); loadCopy(); datagridviewNE1.Refresh(); } }
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { if (reportViewer1.InvokeRequired == true) { reportViewer1.Invoke((MethodInvoker) delegate { try { cotizaciones_local cotizaciones = new cotizaciones_local(); resetReport(cotizaciones); string[] p = e.Argument as string[]; if (p.Length == 7) { string informe = sql.selectRegistroPresupuestos(constants.stringToInt(p[0]), "informe"); reportViewer1.LocalReport.SetParameters(new ReportParameter("informe", informe)); reportViewer1.LocalReport.SetParameters(new ReportParameter("responsable", p[3])); reportViewer1.LocalReport.SetParameters(new ReportParameter("etapa", p[4])); reportViewer1.LocalReport.SetParameters(new ReportParameter("fecha_inicio", p[5])); reportViewer1.LocalReport.SetParameters(new ReportParameter("fecha_entrega", p[6])); var reporte = new datos_reporte() { Cliente = p[1], Nombre_Proyecto = p[2], Fecha = DateTime.Today.ToString("dd/MM/yyyy"), Folio = p[0], Subtotal = 0, IVA = 0, Total = 0 }; cotizaciones.datos_reporte.Add(reporte); cotizaciones.SaveChanges(); } var datos = (from x in cotizaciones.datos_reporte select x); datos_reporteBindingSource.DataSource = datos.ToList(); this.datos_reporteTableAdapter.Fill(this.reportes_dataSet.datos_reporte); this.reportViewer1.LocalReport.Refresh(); this.reportViewer1.RefreshReport(); } catch (Exception err) { MessageBox.Show(err.ToString()); } }); } }
private void loadReporte() { if (reportViewer1.InvokeRequired == true) { reportViewer1.Invoke((MethodInvoker) delegate { reportViewer1.LocalReport.SetParameters(new ReportParameter("Image", constants.getExternalImage("header"))); reportViewer1.LocalReport.SetParameters(new ReportParameter("user", constants.user)); try { cotizaciones_local cotizaciones = new cotizaciones_local(); cotizaciones.Database.ExecuteSqlCommand("TRUNCATE TABLE datos_reporte"); cotizaciones.Database.ExecuteSqlCommand("DBCC CHECKIDENT (datos_reporte, RESEED, 1)"); cotizaciones.Database.ExecuteSqlCommand("TRUNCATE TABLE produccion_t"); cotizaciones.Database.ExecuteSqlCommand("DBCC CHECKIDENT (filas_borradas, RESEED, 1)"); loadData(); var reporte = new datos_reporte() { Cliente = constants.nombre_cotizacion, Nombre_Proyecto = constants.nombre_proyecto, Fecha = DateTime.Today.ToString("dd/MM/yyyy"), Folio = folio.ToString(), }; cotizaciones.datos_reporte.Add(reporte); cotizaciones.SaveChanges(); var datos = (from x in cotizaciones.datos_reporte select x); var datos_2 = (from x in cotizaciones.produccion_t select x); datos_reporteBindingSource.DataSource = datos.ToList(); produccion_tBindingSource.DataSource = datos_2.ToList(); this.datos_reporteTableAdapter.Fill(this.reportes_dataSet.datos_reporte); this.produccion_tTableAdapter.Fill(this.reportes_dataSet.produccion_t); this.reportViewer1.LocalReport.Refresh(); this.reportViewer1.RefreshReport(); } catch (Exception err) { MessageBox.Show(err.ToString()); } }); } }
private void eliminarConfiguraciónToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show(this, "¿Deseas eliminar toda la configuración de integración?", constants.msg_box_caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cotizaciones_local cotizacion = new cotizaciones_local(); var modulos = from x in cotizacion.modulos_cotizaciones where x.merge_id == perso_id select x; if (modulos != null) { foreach (var x in modulos) { x.dir = 0; } cotizacion.SaveChanges(); reloadMergedItems(); } } }
private void button4_Click(object sender, EventArgs e) { cotizaciones_local cotizaciones = new cotizaciones_local(); var data = (from x in cotizaciones.modulos_cotizaciones where x.id == id select x).SingleOrDefault(); if (data != null) { data.dir = 0; cotizaciones.SaveChanges(); if (Application.OpenForms["articulos_cotizacion"] != null) { ((articulos_cotizacion)Application.OpenForms["articulos_cotizacion"]).reloadModulos(); } if (Application.OpenForms["edit_expresss"] != null) { ((edit_expresss)Application.OpenForms["edit_expresss"]).reloadALL(); } this.Close(); } // }
//Sin imagen private void button5_Click(object sender, EventArgs e) { cotizaciones_local cotizaciones = new cotizaciones_local(); var data = (from x in cotizaciones.modulos_cotizaciones where x.id == id select x).SingleOrDefault(); if (data != null) { data.pic = constants.imageToByte(Properties.Resources.blank); data.dir = 3; cotizaciones.SaveChanges(); if (Application.OpenForms["articulos_cotizacion"] != null) { ((articulos_cotizacion)Application.OpenForms["articulos_cotizacion"]).reloadModulos(); } if (Application.OpenForms["edit_expresss"] != null) { ((edit_expresss)Application.OpenForms["edit_expresss"]).reloadALL(); } this.Close(); } }
private void loadAnaliticas() { cotizaciones_local cotizaciones = new cotizaciones_local(); reportViewer1.LocalReport.SetParameters(new ReportParameter("Image", constants.getExternalImage("header"))); if (utilidad > 0) { reportViewer1.LocalReport.SetParameters(new ReportParameter("u_label", "+ Utilidad: " + utilidad + "%")); } else { reportViewer1.LocalReport.SetParameters(new ReportParameter("u_label", " ")); } try { float _utilidad = 0; float _total = 0; float _total_desc = 0; float _sub_total = this.subtotal; //Incluir utilidad if (constants.op9) { _utilidad = this.utilidad > 0 ? (this.utilidad / 100) + 1 : 1; } else { _utilidad = 1; } cotizaciones.Database.ExecuteSqlCommand("TRUNCATE TABLE datos_reporte"); cotizaciones.Database.ExecuteSqlCommand("TRUNCATE TABLE articulos_reporte"); cotizaciones.Database.ExecuteSqlCommand("DBCC CHECKIDENT (datos_reporte, RESEED, 1)"); cotizaciones.Database.ExecuteSqlCommand("DBCC CHECKIDENT (articulos_reporte, RESEED, 1)"); if (descuento > 0) { reportViewer1.LocalReport.SetParameters(new ReportParameter("desc_n", descuento.ToString())); reportViewer1.LocalReport.SetParameters(new ReportParameter("desc_cant", desc_cant.ToString())); reportViewer1.LocalReport.SetParameters(new ReportParameter("descuento", "Descuento: (-" + descuento + "%)")); iva = subtotal * (constants.iva - 1); total = subtotal + iva; } else { reportViewer1.LocalReport.SetParameters(new ReportParameter("desc_cant", "0")); reportViewer1.LocalReport.SetParameters(new ReportParameter("desc_n", "0")); reportViewer1.LocalReport.SetParameters(new ReportParameter("descuento", " ")); } var reporte = new datos_reporte() { Cliente = cliente, Nombre_Proyecto = proyecto, Fecha = DateTime.Today.ToString("dd/MM/yyyy"), Folio = folio, Subtotal = subtotal, IVA = iva, Total = total }; cotizaciones.datos_reporte.Add(reporte); cotizaciones.SaveChanges(); var modulos = from x in cotizaciones.modulos_cotizaciones where x.merge_id <= 0 && x.sub_folio == constants.sub_folio orderby x.orden select x; byte[] p = null; int s = 0; float desperdicio = 0; float flete = 0; float mano_o = 0; float utilidad = 0; float _t = 0; foreach (var c in modulos) { if (c.pic != null) { p = c.pic; Bitmap bm = new Bitmap(constants.byteToImage(p), 100, 85); p = constants.imageToByte(bm); bm = null; } s = 0; desperdicio = 0; flete = 0; mano_o = 0; utilidad = 0; if (c.modulo_id == -1) { int n = c.id; var k = from x in cotizaciones.modulos_cotizaciones where x.merge_id == n select x; foreach (var j in k) { s++; desperdicio = (float)j.desperdicio + desperdicio; flete = (float)j.flete + flete; mano_o = (float)j.mano_obra + mano_o; utilidad = (float)j.utilidad + utilidad; } } if (s > 0) { desperdicio = desperdicio / s; flete = flete / s; mano_o = mano_o / s; utilidad = utilidad / s; } _total = (float)c.total; _total_desc = ((_total) - ((_total) * (descuento / 100))); if (c.modulo_id != -2) { if (utilidad != 0) { utilidad_total = utilidad_total + (_total - (_total / ((utilidad / 100) + 1))); gasto_total = gasto_total + (_total / ((utilidad / 100) + 1)); } else { utilidad_total = utilidad_total + (float)(_total - (_total / ((c.utilidad / 100) + 1))); gasto_total = gasto_total + (float)(_total / ((c.utilidad / 100) + 1)); } if (c.modulo_id != -1) { _t = (float)(_total / ((c.utilidad / 100) + 1)); _t = (float)(_t / ((c.mano_obra / 100) + 1)); _t = (float)(_t / ((c.flete / 100) + 1)); _t = (float)(_t / ((c.desperdicio / 100) + 1)); costo_materiales = costo_materiales + _t; } else { int q = (int)c.id; var u = from x in cotizaciones.modulos_cotizaciones where x.merge_id == q select x; if (u != null) { foreach (var x in u) { _t = (float)(x.total / ((x.utilidad / 100) + 1)); _t = (float)(_t / ((x.mano_obra / 100) + 1)); _t = (float)(_t / ((x.flete / 100) + 1)); _t = (float)(_t / ((x.desperdicio / 100) + 1)); costo_materiales = costo_materiales + _t; } } } } var v = new articulos_reporte() { concepto = c.ubicacion + " - " + c.linea + " - " + c.acabado_perfil, largo = Math.Round((float)c.largo / 1000, 2), alto = Math.Round((float)c.alto / 1000, 2), cantidad = c.cantidad, total = _total, pic = p, desp = desperdicio != 0 ? desperdicio.ToString() : c.desperdicio.ToString(), flete = flete != 0 ? flete.ToString() : c.flete.ToString(), mano_obra = mano_o != 0 ? mano_o.ToString() : c.mano_obra.ToString(), utilidad = utilidad != 0 ? utilidad.ToString() : c.utilidad.ToString(), desc_p = descuento > 0 ? "(-" + descuento + "%)\n$" + _total_desc.ToString("n") : "" }; cotizaciones.articulos_reporte.Add(v); } cotizaciones.SaveChanges(); utilidad_total = utilidad_total + (_sub_total * (this.utilidad / 100)); reportViewer1.LocalReport.SetParameters(new ReportParameter("gasto_total", Math.Round(gasto_total, 2).ToString())); reportViewer1.LocalReport.SetParameters(new ReportParameter("utilidad_total", Math.Round(utilidad_total, 2).ToString())); reportViewer1.LocalReport.SetParameters(new ReportParameter("costo_mats", Math.Round(costo_materiales, 2).ToString())); var datos = (from x in cotizaciones.datos_reporte select x); var datos_2 = (from x in cotizaciones.articulos_reporte select x); datos_reporteBindingSource.DataSource = datos.ToList(); articulos_reporteBindingSource.DataSource = datos_2.ToList(); } catch (Exception err) { MessageBox.Show(err.ToString()); } }
private void insertCopy(int id) { cotizaciones_local cotizaciones = new cotizaciones_local(); var copy = (from x in cotizaciones.copyboxes where x.id == id select x).SingleOrDefault(); if (copy != null) { var paste = new modulos_cotizaciones() { folio = 00000, modulo_id = copy.modulo_id, descripcion = copy.descripcion, mano_obra = copy.mano_obra, dimensiones = copy.dimensiones, acabado_perfil = copy.acabado_perfil, claves_cristales = copy.claves_cristales, cantidad = copy.cantidad, articulo = copy.articulo, linea = copy.linea, diseño = copy.diseño, clave = copy.clave, total = copy.total, largo = copy.largo, alto = copy.alto, flete = copy.flete, utilidad = copy.utilidad, desperdicio = copy.desperdicio, claves_otros = copy.claves_otros, claves_herrajes = copy.claves_herrajes, ubicacion = copy.ubicacion, pic = copy.pic, claves_perfiles = copy.claves_perfiles, merge_id = copy.merge_id, concept_id = copy.concept_id, sub_folio = constants.sub_folio, dir = copy.dir, news = copy.news, new_desing = copy.new_desing, orden = constants.getCountPartidas() }; cotizaciones.modulos_cotizaciones.Add(paste); //Remove copy from copybox if (!checkBox1.Checked) { cotizaciones.copyboxes.Remove(copy); } cotizaciones.SaveChanges(); if (copy.modulo_id == -1) { int last = 0; var g = (from x in cotizaciones.modulos_cotizaciones orderby x.id descending select x).FirstOrDefault(); if (g != null) { last = g.id; } var last_m = (from x in cotizaciones.modulos_cotizaciones where x.id == last select x).SingleOrDefault(); if (last_m != null) { last_m.concept_id = last; var copy_m = from x in cotizaciones.copyboxes where x.merge_id == id select x; if (copy_m != null) { foreach (var v in copy_m) { var paste_m = new modulos_cotizaciones() { folio = 00000, modulo_id = v.modulo_id, descripcion = v.descripcion, mano_obra = v.mano_obra, dimensiones = v.dimensiones, acabado_perfil = v.acabado_perfil, claves_cristales = v.claves_cristales, cantidad = v.cantidad, articulo = v.articulo, linea = v.linea, diseño = v.diseño, clave = v.clave, total = v.total, largo = v.largo, alto = v.alto, flete = v.flete, utilidad = v.utilidad, desperdicio = v.desperdicio, claves_otros = v.claves_otros, claves_herrajes = v.claves_herrajes, ubicacion = v.ubicacion, pic = v.pic, claves_perfiles = v.claves_perfiles, merge_id = last, concept_id = v.concept_id, sub_folio = constants.sub_folio, dir = v.dir, news = v.news, new_desing = v.new_desing, orden = 0 }; cotizaciones.modulos_cotizaciones.Add(paste_m); cotizaciones.copyboxes.Remove(v); } } } } cotizaciones.SaveChanges(); loadCopy(); datagridviewNE1.Refresh(); ((Form1)Application.OpenForms["form1"]).reloadAll(this); ((Form1)Application.OpenForms["form1"]).refreshNewArticulo(5); if (Application.OpenForms["articulos_cotizacion"] != null) { ((articulos_cotizacion)Application.OpenForms["articulos_cotizacion"]).resetRowSelect(); ((articulos_cotizacion)Application.OpenForms["articulos_cotizacion"]).loadALL(); } if (datagridviewNE1.RowCount == 0) { cotizaciones.Database.ExecuteSqlCommand("TRUNCATE TABLE copybox"); cotizaciones.Database.ExecuteSqlCommand("DBCC CHECKIDENT (copybox, RESEED, 1)"); this.Close(); } } }