private void btnguardar_Click(object sender, EventArgs e) { if (AccesoInternet() == false) { MessageBox.Show("No hay internet, intente en un momento"); return; } double i = 0; string s = textBox1.Text; bool result = double.TryParse(s, out i); //i now = 108 if (result == false) { MessageBox.Show("Ingrese un porcentaje valido"); return; } string status = "Se le aumentara el precio a los productos ¿Desea continuar?"; string leyenda = "Aumentar precio"; DialogResult resultado = MessageBox.Show(status, leyenda, MessageBoxButtons.YesNo); if (resultado == DialogResult.No) { return; } if (Convert.ToDouble(textBox1.Text) > 0) { double inflacion = 1 + (Convert.ToDouble(textBox1.Text) / 100); DbObject prod = new DbObject(); int año = DateTime.Now.Year; año--; string fecha = año.ToString() + "-03-01"; if (cambio == "1") { if (cmbmarca.SelectedIndex != -1) { prod.actualizarprecio("precioAlmacen", inflacion.ToString(), "MARCA='" + cmbmarca.SelectedItem + "' and STOCK>0 and FECHA_FACTURA>'" + fecha + "' and FECHA_FACTURA<'" + DateTime.Now.Year.ToString() + "06-01'"); } else { return; } } else { prod.actualizarprecio("precioAlmacen", inflacion.ToString(), "STOCK>0 and FECHA_FACTURA BETWEEN'" + fecha + "' and '" + DateTime.Now.Year.ToString() + "-06-01'"); prod.actualizarinflacion("Update inflacion SET fecha=CURDATE(), cambio='1' WHERE Id=1"); } this.Close(); } }
private void FormInflacion_Load(object sender, EventArgs e) { if (AccesoInternet() == false) { MessageBox.Show("No hay internet, intente en un momento"); return; } DbObject db = new DbObject(); cambio = db.datoinfla(); if (cambio == "1") { cmbmarca.DataSource = productos.listamarcas(); cmbmarca.SelectedIndex = -1; } else { cmbmarca.Visible = false; label4.Text = "Actualizar precios para todos los productos en stock"; } }
private void FormProductoSpec_Load(object sender, EventArgs e) { tablacodigos = prdoducto_codigos.tabla(CATALOGO.Text, productoSeleccionadoi.Id.ToString()); string rutaDataSheet = @"DataSheet\" + productoSeleccionadoi.CATALOGO + ".pdf"; if (File.Exists(rutaDataSheet)) { buttonDataSheet.BackColor = System.Drawing.Color.GreenYellow; productoSeleccionadoi.ADJUNTOS = productoSeleccionadoi.CATALOGO; productoSeleccionadoi.Update("Id"); } if (productoSeleccionadoi.DOCUMENTOS != "") { button3.BackColor = System.Drawing.Color.GreenYellow; } button2.Visible = false; if (AccesoInternet() == false) { MessageBox.Show("No hay internet, intente en un momento"); return; } if (productoSeleccionadoi == null) { nuevo2 = true; productoSeleccionadoi = new productos(); } productoSeleccionadoi.MostrarValores(this, false); DESCRIPCION.Text = productoSeleccionadoi.DESCRIPCION; double precio_oferta = productoSeleccionadoi.PrecioAlmacen; if (productoSeleccionadoi.STOCKMUERTO == 1) { ckmuerto.Checked = true; precio_oferta = Math.Round(precio_oferta * 0.5, 2); } double porcentaje37 = precio_oferta * 1.37; double porcentaje50 = precio_oferta * 1.5; PrecioAlmacen.Text = precio_oferta.ToString(); textBox37.Text = porcentaje37.ToString(); textBox50.Text = porcentaje50.ToString(); labelActualizacion.Text = productoSeleccionadoi.FECHA_FACTURA.ToShortDateString(); DateTime oldDate = productoSeleccionadoi.FECHA_FACTURA; DateTime newDate = DateTime.Now; // Difference in days, hours, and minutes. TimeSpan ts = newDate - oldDate; // Difference in days. int differenceInDays = ts.Days; //MessageBox.Show(newDate.Date.ToShortDateString()+" "+oldDate.Date.ToShortDateString()+" "+ differenceInDays.ToString()); rutaImagen = @"IMAGEN\" + productoSeleccionadoi.CATALOGO + ".jpg"; if (File.Exists(rutaImagen)) { fs = new FileStream(rutaImagen, FileMode.Open, FileAccess.Read); Bitmap imagen = (Bitmap)System.Drawing.Image.FromStream(fs); double ladoMaximo = 450; double factorReduccion; double factorAltoAncho = (double)imagen.Height / (double)imagen.Width; if (imagen.Width > ladoMaximo || imagen.Height > 450) { if (factorAltoAncho >= 1) { factorReduccion = 450 / imagen.Height; } else { } } pictureBox1.Image = imagen; fs.Close(); } else { fs = new FileStream(rutaLogo, FileMode.Open, FileAccess.Read); pictureBox1.Image = System.Drawing.Image.FromStream(fs); fs.Close(); } int diferencia = 0; /*if (DateTime.Now.Month < 4) * diferencia = 90; * else if (DateTime.Now.Month == 4) * diferencia = 90; * else if (DateTime.Now.Month == 5) * diferencia = 90; * else if (DateTime.Now.Month == 6) * diferencia = 90; * else if (DateTime.Now.Month ==7) * diferencia = 120; * else if (DateTime.Now.Month == 8) * diferencia = 150; * else if (DateTime.Now.Month > 8) * diferencia = 180;*/ diferencia = 180; if (differenceInDays > diferencia) { PrecioAlmacen.Visible = false; textBox37.Visible = false; textBox50.Visible = false; } if (productoSeleccionadoi.STOCKMUERTO == 1) { PrecioAlmacen.Visible = true; textBox37.Visible = true; textBox50.Visible = true; } DbObject db = new DbObject(); string cambio = db.datoinfla(); /* if (productoSeleccionadoi.STOCK == 0) * { * labelAdvertencia1.Visible = true; * PrecioAlmacen.Visible = false; * textBox37.Visible = false; * textBox50.Visible = false; * }*/ /*if (cambio == "0") * { * labelAdvertencia1.Visible = true; * labelAdvertencia1.Text = "Agrege el porcentaje de inflacion"; * PrecioAlmacen.Visible = false; * textBox37.Visible = false; * textBox50.Visible = false; * }*/ // MessageBox.Show(DateTime.Now.Month.ToString()); //MessageBox.Show(productoSeleccionadoi.Id.ToString()); ADJUNTOS.Text = productoSeleccionadoi.ADJUNTOS; var a1 = productoSeleccionadoi.ADJUNTOS; string[] adjuntos = a1.Split(','); for (int i = 0; i < adjuntos.Count(); i++)//mustra adjuntos { if (adjuntos[i] != "") { //comboBox1.Items.Add(adjuntos[i]); } } }
public string facturaproyecto(DbObject objectToAutonumber, string Key) { string n = "0"; Type tipo = objectToAutonumber.GetType(); string tabla = tipo.Name.ToLower(); if (objectToAutonumber.Table != "") { tabla = objectToAutonumber.Table; } switch (DataBaseProvider) { case TypeOfDataBase.MicrosoftAccess: query = "SELECT TOP 1 " + Key + " FROM " + tabla + " ORDER BY " + Key + " DESC"; try { oleDbConnection.Open(); } catch (Exception ex) { error = ex.Message; return("0"); } OleDbCommand cmd = new OleDbCommand(query, oleDbConnection); try { object o = cmd.ExecuteScalar(); if (o == null) { return("0"); } n = (string)(o); } catch (Exception ex) { error = ex.Message; return("0"); } finally { oleDbConnection.Close(); } break; case TypeOfDataBase.MicrosoftSqlServer: query = "SELECT " + Key + " FROM " + tabla + " ORDER BY " + Key + " DESC LIMIT 1"; break; case TypeOfDataBase.MySqlServer: query = "SELECT folio FROM " + tabla + " where origen='PREFACTURA PROYECTOS' and idproyecto=" + Key + " LIMIT 1"; try { mysqlconn.Open(); } catch (Exception ex) { error = ex.Message; return("0"); } MySqlCommand cmd2 = new MySqlCommand(query, mysqlconn); try { object o = cmd2.ExecuteScalar(); if (o == null) { return("0"); } n = o.ToString(); } catch (Exception ex) { error = ex.Message; return("0"); } finally { mysqlconn.Close(); } break; } return(n); }
public int NextNumber(DbObject objectToAutonumber, string Key) { int n = 0; Type tipo = objectToAutonumber.GetType(); string tabla = tipo.Name.ToLower(); if (objectToAutonumber.Table != "") { tabla = objectToAutonumber.Table; } switch (DataBaseProvider) { case TypeOfDataBase.MicrosoftAccess: query = "SELECT TOP 1 " + Key + " FROM " + tabla + " ORDER BY " + Key + " DESC"; try { oleDbConnection.Open(); } catch (Exception ex) { error = ex.Message; return(-1); } OleDbCommand cmd = new OleDbCommand(query, oleDbConnection); try { object o = cmd.ExecuteScalar(); if (o == null) { return(1); } n = (int)(o); } catch (Exception ex) { error = ex.Message; return(-1); } finally { oleDbConnection.Close(); } break; case TypeOfDataBase.MicrosoftSqlServer: query = "SELECT " + Key + " FROM " + tabla + " ORDER BY " + Key + " DESC LIMIT 1"; break; case TypeOfDataBase.MySqlServer: query = "SELECT " + Key + " FROM " + tabla + " ORDER BY " + Key + " DESC LIMIT 1"; try { mysqlconn.Open(); } catch (Exception ex) { error = ex.Message; return(-1); } MySqlCommand cmd2 = new MySqlCommand(query, mysqlconn); try { object o = cmd2.ExecuteScalar(); if (o == null) { return(1); } n = (int)(o); } catch (Exception ex) { error = ex.Message; return(-1); } finally { mysqlconn.Close(); } break; } return(n + 1); }
public void Delete(object objectToDelete, string where) { error = ""; Type tipo = objectToDelete.GetType(); string Tabla = objectToDelete.GetType().Name.ToLower(); try { DbObject dbO = (DbObject)objectToDelete; if (dbO.Table != "") { Tabla = dbO.Table; } } catch { } query = "DELETE FROM " + Tabla + " WHERE " + where; switch (DataBaseProvider) { case TypeOfDataBase.MicrosoftAccess: oleDbConnection.Open(); OleDbCommand cmd = new OleDbCommand(query, oleDbConnection); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { error = ex.Message; } finally { oleDbConnection.Close(); } break; case TypeOfDataBase.MicrosoftSqlServer: error = "Not Implemented"; break; case TypeOfDataBase.MySqlServer: mysqlconn.Open(); MySqlCommand cmd2 = new MySqlCommand(query, mysqlconn); try { cmd2.ExecuteNonQuery(); } catch (Exception ex) { error = ex.Message; } finally { mysqlconn.Close(); } break; } }
private void Form1_Load(object sender, EventArgs e) { MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder(); sb.Server = "secure199.inmotionhosting.com"; sb.UserID = "abdsto5_felipe"; sb.Password = "******"; sb.Database = "abdsto5_cotizaciones"; //PRUEBAS EN LOCALHOST /* * sb.Server = "localhost"; * sb.UserID = "felipe"; * sb.Password = "******"; * sb.Database = "ejemplo"; */ bdMysql = new DataBase(); bdMysql.DataBaseProvider = TypeOfDataBase.MySqlServer; bdMysql.ConnectionString = sb.ToString(); // bdMysql.ConnectionString = "Server = localhost; Database = descobi; Uid = felipe; Pwd = 1945Inadescobi"; bdMysql.CreateConnection(); DbObject.DefaultDataBaseObject = bdMysql; dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick); /* * String mac = "00:12:3F:43:98:52"; * String mac2 = ""; * String tarjeta = "Controladora Gigabit Broadcom NetXtreme 57xx"; * ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_NetworkAdapter where Name='" + tarjeta + "'"); * ManagementObjectCollection moc = mos.Get(); * if (moc.Count > 0) * { * foreach (ManagementObject mo in moc) * { * mac2 = (string)mo["MACAddress"]; * // MessageBox.Show(mac); * } * } * else * { * MessageBox.Show("Esta Aplicacion no coincide con el equipo, Favor de actualizarla"); * this.Close(); * } * * if (mac != mac2) * { * MessageBox.Show("Esta Aplicacion no coincide con el equipo, Favor de actualizarla"); * this.Close(); * } */ DbObject db = new DbObject(); string cambio = db.añoinflacion(); if (cambio != DateTime.Now.Year.ToString()) { bdMysql.editarinflacion("Update inflacion SET fecha=CURDATE(), cambio='0' WHERE Id=1"); } lista = clientes.GetExistentes(); DgieWS TCambio = new DgieWS(); string strTDCambio = TCambio.tiposDeCambioBanxico(); XElement root = XElement.Parse(@strTDCambio); XNamespace bm = "http://www.banxico.org.mx/structure/key_families/dgie/sie/series/compact"; IEnumerable <XElement> address = from el in root.Descendants(bm + "DataSet").Elements(bm + "Series") where (string)el.Attribute("IDSERIE") == "SF43718" select el; foreach (XElement el in address) { tc = "" + el.Element(bm + "Obs").Attribute("OBS_VALUE").Value; } try { Convert.ToDouble(tc); } catch { tc = "0"; } }