private void button1_Click(object sender, EventArgs e) { if (!validacion()) { return; } rango c = new rango(); c.mat = _id; c.rini = Convert.ToInt32(this.numericUpDown2.Text); c.rfin = Convert.ToInt32(this.numericUpDown1.Text); c.precio = Convert.ToDecimal(this.textBox1.Text); int recibe = 0; //if (string.IsNullOrEmpty(_id)) recibe = op_rangos.accion(c, 1); //else //{ // this.textBox1.ReadOnly = true; // recibe = op_rangos.accion(c, 2); //} if (recibe > 0) { MessageBox.Show("Registro Grabado"); operacion(); button1.Enabled = false; //this.label10.Text = "EMPLEADO: " + c.NombreCompleto; } }
// devuleve un registro en particular public static rango GellIdrango(string c) { rango list = null; using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString())) { conn.Open(); MySqlCommand cmd; cmd = new MySqlCommand("SELECT * FROM rangos_mat WHERE codmat like @cod", conn); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@cod", c); MySqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { list = Loadrango(reader); } } } return(list); }
// Escribe los valores en la clase cargos private static rango Loadrango(IDataReader reader) { rango item = new rango(); item.mat = Convert.ToString(reader["codmat"]); item.rini = Convert.ToInt32(reader["rini"]); item.rfin = Convert.ToInt32(reader["rfin"]); item.precio = Convert.ToDecimal(reader["precio"]); return(item); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.ColumnIndex >= 0) { DataGridViewRow row = dataGridView1.CurrentRow as DataGridViewRow; //this.toolStripLabel1.Text = row.Cells[0].Value.ToString(); if (this.dataGridView1.Columns[e.ColumnIndex].Name == "eli") { int a = Convert.ToInt32(MessageBox.Show("Está seguro que desea eliminar el registro", Application.ProductName.ToString(), MessageBoxButtons.YesNo, MessageBoxIcon.Information)); if (a == 6) { rango c = new rango(); c.mat = row.Cells[0].Value.ToString(); c.rini = int.Parse(row.Cells[1].Value.ToString()); c.rfin = int.Parse(row.Cells[2].Value.ToString()); op_rangos.accion(c, 3); dataGridView1.AutoGenerateColumns = false; dataGridView1.DataSource = op_rangos.GellAllrango3("select * from rangos_mat where codmat='" + c.mat + "'"); } } } } catch (MySqlException ex) { if (ex.Number == 1451) { MessageBox.Show("El dato está siendo utilizado, por lo tanto es imposible de eliminar", Application.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show(ex.Message, Application.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
// hace las operaciones correspondiente al procedimiento almacenado. public static int accion(rango c, int op) { int rowsAffected = 0; try { using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString())) { con.Open(); MySqlCommand command = new MySqlCommand("SP_rango", con); command.CommandType = CommandType.StoredProcedure; MySqlParameter paramId = new MySqlParameter("msj", MySqlDbType.Int32); paramId.Direction = ParameterDirection.Output; command.Parameters.Add(paramId); command.Parameters.AddWithValue("codmat1", c.mat); command.Parameters.AddWithValue("rini1", c.rini); command.Parameters.AddWithValue("rfin1", c.rfin); command.Parameters.AddWithValue("precio1", c.precio); command.Parameters.AddWithValue("opc", op); command.ExecuteNonQuery(); rowsAffected = int.Parse(command.Parameters["msj"].Value.ToString()); } } catch (MySqlException ex) { MessageBox.Show("Error de acceso a datos: " + ex.Message.ToString(), Application.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex1) { MessageBox.Show("Error: " + ex1.Message.ToString(), Application.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } return(rowsAffected); }
public void separacion(ref List<double> nNum, ref double fe) { if (Convert.ToInt32(textBox1.Text) < 12) { tableLayoutPanel1.AutoScroll = false; } else { tableLayoutPanel1.AutoScroll = true; } tableLayoutPanel1.Controls.Clear(); int n = Convert.ToInt32(textBox1.Text); tableLayoutPanel1.ColumnCount = n; TableLayoutColumnStyleCollection styles = this.tableLayoutPanel1.ColumnStyles; foreach (ColumnStyle style in styles) { style.SizeType = SizeType.Percent; style.Width = 100 / n; } List<rango> nRang = new List<rango>(); for (int i = 0; i < n; i++) { rango r = new rango(); Label lb = new Label(); lb.Text = fe.ToString(); Label lab = new Label(); Label cont = new Label(); int valor = Convert.ToInt32(textBox5.Text); r.min = Math.Round((((i) * fe)/valor), 3); r.max = Math.Round((((i + 1) * fe) /valor) , 3); lab.Text = r.min.ToString() + " - " + r.max.ToString(); cont.Text = "0"; tableLayoutPanel1.Controls.Add(lb, i, 0); tableLayoutPanel1.Controls.Add(lab, i, 2); tableLayoutPanel1.Controls.Add(cont, i, 1); nRang.Add(r); } foreach (var y in nNum) { for (int i = 0; i < nRang.Count; i++) { if (nRang[i].min <= y && y < nRang[i].max) { Label lab = (Label)tableLayoutPanel1.GetControlFromPosition(i, 1); lab.Text = (Convert.ToInt32(lab.Text) + 1).ToString(); } } } label3.Text = nNum.Count.ToString(); List<sumatoria> nSum = new List<sumatoria>(); double storia = 0; for (int i = 0; i < tableLayoutPanel1.ColumnCount; i++) { Label lb = (Label)tableLayoutPanel1.GetControlFromPosition(i, 1); sumatoria s = new sumatoria(); s.fo = Convert.ToDouble(lb.Text); nSum.Add(s); s.r = s.fo - fe; s.r = s.r * s.r; storia += s.r; } storia = (1.00 / fe) * storia; storia = Math.Round(storia, 5); textBox3.Text = storia.ToString(); }
public void separacion(ref List <double> nNum, ref double fe) { if (Convert.ToInt32(textBox1.Text) < 12) { tableLayoutPanel1.AutoScroll = false; } else { tableLayoutPanel1.AutoScroll = true; } tableLayoutPanel1.Controls.Clear(); int n = Convert.ToInt32(textBox1.Text); tableLayoutPanel1.ColumnCount = n; TableLayoutColumnStyleCollection styles = this.tableLayoutPanel1.ColumnStyles; foreach (ColumnStyle style in styles) { style.SizeType = SizeType.Percent; style.Width = 100 / n; } List <rango> nRang = new List <rango>(); for (int i = 0; i < n; i++) { rango r = new rango(); Label lb = new Label(); lb.Text = fe.ToString(); Label lab = new Label(); Label cont = new Label(); int valor = Convert.ToInt32(textBox5.Text); r.min = Math.Round((((i) * fe) / valor), 3); r.max = Math.Round((((i + 1) * fe) / valor), 3); lab.Text = r.min.ToString() + " - " + r.max.ToString(); cont.Text = "0"; tableLayoutPanel1.Controls.Add(lb, i, 0); tableLayoutPanel1.Controls.Add(lab, i, 2); tableLayoutPanel1.Controls.Add(cont, i, 1); nRang.Add(r); } foreach (var y in nNum) { for (int i = 0; i < nRang.Count; i++) { if (nRang[i].min <= y && y < nRang[i].max) { Label lab = (Label)tableLayoutPanel1.GetControlFromPosition(i, 1); lab.Text = (Convert.ToInt32(lab.Text) + 1).ToString(); } } } label3.Text = nNum.Count.ToString(); List <sumatoria> nSum = new List <sumatoria>(); double storia = 0; for (int i = 0; i < tableLayoutPanel1.ColumnCount; i++) { Label lb = (Label)tableLayoutPanel1.GetControlFromPosition(i, 1); sumatoria s = new sumatoria(); s.fo = Convert.ToDouble(lb.Text); nSum.Add(s); s.r = s.fo - fe; s.r = s.r * s.r; storia += s.r; } storia = (1.00 / fe) * storia; storia = Math.Round(storia, 5); textBox3.Text = storia.ToString(); }