Esempio n. 1
0
        // devuleve un registro en particular
        public static materiales GellIdMateriales(string c, int i)
        {
            materiales list = null;

            using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))
            {
                conn.Open();
                MySqlCommand cmd;
                if (i == 1)
                {
                    cmd = new MySqlCommand("SELECT * FROM materiales WHERE cod like @cod", conn);
                }
                else
                {
                    cmd = new MySqlCommand("SELECT * FROM materiales WHERE nom like @cod", conn);
                }

                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@cod", c);


                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows == true)
                {
                    while (reader.Read())
                    {
                        list = LoadMateriales(reader);
                    }
                }
            }

            return(list);
        }
Esempio n. 2
0
        // hace las operaciones correspondiente al procedimiento almacenado.
        public static int accion(materiales c, int op)
        {
            int rowsAffected = 0;

            try
            {
                using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["default"].ToString()))
                {
                    con.Open();
                    MySqlCommand command = new MySqlCommand("SP_materiales", con);
                    command.CommandType = CommandType.StoredProcedure;

                    MySqlParameter paramId = new MySqlParameter("msj", MySqlDbType.Int32);
                    paramId.Direction = ParameterDirection.Output;
                    command.Parameters.Add(paramId);

                    command.Parameters.AddWithValue("cod1", c.cod);
                    command.Parameters.AddWithValue("nom1", c.nom);
                    command.Parameters.AddWithValue("tip1", c.tip);
                    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);
        }
        // GET: Materiales/Edit/5
        public ActionResult Edit(int id)
        {
            ViewBag.idtipo = new SelectList(db.tipo, "idTipo", "nombre");
            materiales m = db.materiales.Find(id);

            return(View(m));
        }
Esempio n. 4
0
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.ColumnIndex >= 0)
         {
             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)
                 {
                     DataGridViewRow row = dataGridView1.CurrentRow as DataGridViewRow;
                     materiales      c   = new materiales();
                     c.cod = row.Cells[1].Value.ToString();
                     op_materiales.accion(c, 3);
                     dataGridView1.AutoGenerateColumns = false;
                     dataGridView1.DataSource          = op_materiales.GellAllMateriales();
                     this.toolStripStatusLabel1.Text   = dataGridView1.RowCount.ToString();
                 }
             }
         }
     }
     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);
         }
     }
 }
Esempio n. 5
0
        // Escribe los valores en la clase cargos

        private static materiales LoadMateriales(IDataReader reader)
        {
            materiales item = new materiales();

            item.cod = Convert.ToString(reader["cod"]);
            item.nom = Convert.ToString(reader["nom"]);
            item.tip = Convert.ToString(reader["tip"]);
            return(item);
        }
 public ActionResult Create(materiales m)
 {
     try
     {
         // TODO: Add insert logic here
         db.materiales.Add(m);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
 public ActionResult Edit(int id, FormCollection formValues)
 {
     try
     {
         // TODO: Add update logic here
         ViewBag.idtipo = new SelectList(db.tipo, "idTipo", "nombre");
         materiales m = db.materiales.Find(id);
         UpdateModel(m);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Esempio n. 8
0
        public int SaveMaterial(materiales m)
        {
            WarehouseEntities data = new WarehouseEntities();
            int res = 0;

            data.materiales.Add(m);

            try
            {
                res = data.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Excepción guardando material: " + ex.Message);
            }
            return(res);
        }
Esempio n. 9
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (!validacion())
            {
                return;
            }

            materiales c = new materiales();

            c.tip = this.comboBox1.SelectedValue.ToString();
            c.cod = string.Concat(this.textBox3.Text, "-", this.textBox2.Text.PadLeft(4, '0'));
            c.nom = this.textBox1.Text;



            int rowsAffected = 0;

            if (string.IsNullOrEmpty(_id))
            {
                rowsAffected  = op_materiales.accion(c, 1);
                op_var.boton3 = true;
            }
            else
            {
                this.textBox1.ReadOnly = true;
                rowsAffected           = op_materiales.accion(c, 2);
            }

            if (rowsAffected > 0)
            {
                if (rowsAffected == 1)
                {
                    MessageBox.Show(mensajes.MsjProc1, Application.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    operacion();
                    this.toolStripButton3.Visible = true;
                    toolStripButton2.Visible      = false;
                    this.panel1.Enabled           = true;
                }
                if (rowsAffected == 2)
                {
                    MessageBox.Show(mensajes.MsjProc2, Application.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    operacion();
                    this.toolStripButton3.Visible = true;
                    toolStripButton2.Visible      = false;
                    this.panel1.Enabled           = true;
                }
                if (rowsAffected == 3)
                {
                    MessageBox.Show(mensajes.MsjProc3, Application.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    operacion();
                    this.toolStripButton3.Visible = true;
                    toolStripButton2.Visible      = false;
                }
                if (rowsAffected == 4)
                {
                    if (MessageBox.Show(mensajes.MsjProc4 + " " + mensajes.MsjProc5, Application.ProductName.ToString(), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        rowsAffected = op_materiales.accion(c, 2);
                    }
                }
            }
            else
            {
                MessageBox.Show(mensajes.MsjProc0, Application.ProductName.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Esempio n. 10
0
        private void frmmateriales_Load(object sender, EventArgs e)
        {
            IntPtr hmenu = GetSystemMenu(this.Handle, 0);
            int    cnt   = GetMenuItemCount(hmenu);

            // remove 'close' action
            RemoveMenu(hmenu, cnt - 1, MF_DISABLED | MF_BYPOSITION);
            // remove extra menu line
            RemoveMenu(hmenu, cnt - 2, MF_DISABLED | MF_BYPOSITION);
            DrawMenuBar(this.Handle);

            comboBox1.DataSource    = op_documentos.tipo_produccion();
            comboBox1.DisplayMember = "nom";
            comboBox1.ValueMember   = "cod";
            comboBox1.Text          = null;
            this.textBox3.Text      = null;


            if (!string.IsNullOrEmpty(_id))
            {
                materiales c = op_materiales.GellIdMateriales(_id, 1);

                if (c != null)
                {
                    this.Text                              = "Editando Material: " + c.cod + "-" + c.nom;
                    this.textBox1.Text                     = c.nom;
                    this.textBox3.Text                     = c.cod.Substring(1, 2);
                    this.textBox2.Text                     = c.cod.Substring(4, 4);
                    this.comboBox1.SelectedValue           = c.tip;
                    this.dataGridView1.AutoGenerateColumns = false;
                    this.dataGridView1.DataSource          = op_rangos.GellAllrango3("select * from rangos_mat where codmat='" + c.cod + "'");;
                    this.panel1.Enabled                    = false;
                    //toolStripButton5.Visible = true;
                    toolStripButton1.Visible = false;

                    operacion();
                    toolStripButton3.Visible = false;
                    foreach (Control u in this.Controls)
                    {
                        if (u is Button)
                        {
                            u.Enabled = true;
                        }
                    }
                }
            }
            else
            {
                foreach (Control u in this.Controls)
                {
                    if (u is Button)
                    {
                        u.Enabled = false;
                    }
                }
                this.Text                = "Nuevo Registro de Material";
                this.panel1.Enabled      = false;
                toolStripButton3.Visible = false;
                toolStripButton5.Visible = false;
                toolStripButton1.Visible = true;
            }
        }