コード例 #1
0
 public bool agregarmaterialS(MATERIAL_S nuevo)
 {
     try
     {
         modelo.MATERIAL_S.Add(nuevo);
         return(modelo.SaveChanges() > 0);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #2
0
 protected void btnconfirmarmaterialp_Click(object sender, EventArgs e)
 {
     if (txtcmr.Text.Equals("") || txtcmd.Text.Equals(""))
     {
         lbmaterial.Text = "rellene los campos";
         mm1.Show();
     }
     else
     {
         string   mnombre  = txtcmn.Text;
         string   mtipo    = txtcmt.Text;
         string   mmedida  = txtcmm.Text;
         int      mid      = Convert.ToInt32(lbid2.Text);
         int      mcana    = Convert.ToInt32(lbcantidadp.Text);
         DateTime fecha    = DateTime.Now;
         int      mcann    = Convert.ToInt32(txtcmc.Text);
         string   mrespons = txtcmr.Text;
         string   mdetalle = txtcmd.Text;
         int      ns       = mcana - mcann;
         if (mcann != 0)
         {
             if (ns >= 0)
             {
                 MATERIAL nuevo = new MATERIAL
                 {
                     ID_MATERIAL = mid,
                     NOMBRE      = mnombre,
                     TIPO        = mtipo,
                     MEDIDA      = mmedida,
                     CANTIDAD    = ns
                 };
                 if (con.Actualizarmaterial(nuevo))
                 {
                     MATERIAL_S nuevos = new MATERIAL_S
                     {
                         ID_MATERIAL = mid,
                         FECHA       = fecha,
                         OPERADOR    = mrespons,
                         CANTIDAD_SM = mcann,
                         DETALLE     = mdetalle
                     };
                     if (con.agregarmaterialS(nuevos))
                     {
                         lbmaterial.Text = "material prestado correctamente";
                         txtcmn.Visible  = false;
                         txtcmt.Visible  = false;
                         txtcmm.Visible  = false;
                         txtcmc.Visible  = false;
                         txtcmr.Visible  = false;
                         txtcmd.Visible  = false;
                         txtcmn.Text     = "";
                         txtcmt.Text     = "";
                         txtcmm.Text     = "";
                         txtcmc.Text     = "";
                         txtcmr.Text     = "";
                         txtcmd.Text     = "";
                         btnconfirmarmaterialp.Visible = false;
                         gvmaterial.DataSource         = con.buscarmaterial(txtbuscarm.Text, txtbuscart.Text);
                         gvmaterial.DataBind();
                         gvmaterial.Visible = true;
                         mm1.Show();
                     }
                 }
             }
             else
             {
                 lbmaterial.Text = "no dispone de tanto material";
                 mm1.Show();
             }
         }
         else
         {
             lbmaterial.Text = "tiene que asignar una cantidad mayor a 0";
             txtcmc.Text     = "";
             mm1.Show();
         }
     }
 }