protected void BtnGuardar_Click(object sender, EventArgs e) { //decimal costo = txtCosto.Text != "" && txtCosto != null ? Convert.ToDecimal(txtCosto.Text) : 0; try { if (FU.HasFile) { string ext = System.IO.Path.GetExtension(FU.FileName); ext = ext.ToLower(); FU.SaveAs(Server.MapPath("~/img/" + FU.FileName)); Response.Write("Se subió el archivo"); } Proyecto proye = new Proyecto() { //id_proyecto = Convert.ToInt32(txtId.Value), nombre_proyecto = txtNombre.Text, desc_proyecto = txtDescripcion.Text, img_proyecto = FU.FileName, fecha_proyecto = Convert.ToDateTime(txtDate.Text), costo_proyecto = Convert.ToInt32(txtCosto.Text) }; if (txtId.Value == "" || txtId.Value == null) { new BusGlobal().CreateProyecto(proye); Response.Redirect("Proyectos.aspx", false); } else { proye.id_proyecto = Convert.ToInt32(txtId.Value); new BusGlobal().UpdateProyecto(proye); Response.Redirect("Proyectos.aspx", false); } } catch (Exception ex) { throw new ApplicationException(ex.Message); } }
protected void butUpload_Click(object sender, EventArgs e) { int c = 0; if (FU.HasFile) { string s = FU.FileName; int i = s.Length; string sa = s.Substring((i - 4), 4); cmd.CommandText = "select count(T_code) from Course_Material where T_code='" + txtcode.Text + "'"; con.Open(); if (cmd.ExecuteScalar() == null) { c = 1; } else { c = Convert.ToInt32(cmd.ExecuteScalar()) + 1; } string s1 = txtcode.Text + Convert.ToString(c) + sa; FU.SaveAs(Server.MapPath("~/") + "/Materials/" + s1); cmd.Connection = con; cmd.CommandText = "Insert into Course_Material values('" + txtcode.Text + "','" + s1 + "')"; if (con.State == ConnectionState.Closed) { con.Open(); } cmd.ExecuteNonQuery(); txtcode.Text = ""; txtcrs.Text = ""; txtSub.Text = ""; txtYSem.Text = ""; con.Close(); } }
protected void Submit_Click(object sender, EventArgs e) { Product product; Labeloldprod.Text = ""; try { string productName = productNameTB.Text; double productPrice = Convert.ToDouble(productPriceTB.Text); string CategoryName = productCategoryDDL.SelectedValue; int productInventory = Convert.ToInt32(productInventoryTB.Text); string name = FU.FileName; string ProductFilePath = ""; string SavedFileName = ""; if ((name == "" && Session["oldProduct"] != null)) { ProductFilePath = productImg.ImageUrl; } else { SavedFileName = Server.MapPath(".") + "/images/" + name; ProductFilePath = "images/" + name; FU.SaveAs(SavedFileName); } bool productStatus; if (statusCB.Checked == true) { productStatus = true; } else { productStatus = false; } if (Session["oldProduct"] != null) { product = new Product(productName, productPrice, CategoryName, productInventory, ProductFilePath, productStatus, (int)Session["product_id"]); } else { product = new Product(productName, productPrice, CategoryName, productInventory, ProductFilePath, productStatus); } } catch (Exception ex) { messageLBL.Text = "invalid argoments inserted " + ex.Message; return; } try { if (Session["oldProduct"] != null) { product.updateTable(); try { product.updateDatabase(); Session["oldProduct"] = null; messageLBL.Text = "you changed " + productNameTB.Text + " product successfully"; } catch (Exception ex) { Response.Write("Error updating the products database " + ex.Message); } } else { int numEffected = product.insertProduct(); messageLBL.Text = "you added " + numEffected.ToString() + " new product"; } } catch (Exception ex) { messageLBL.Text = "An error accured " + ex.Message; } productNameTB.Text = ""; productPriceTB.Text = ""; productInventoryTB.Text = ""; statusCB.Checked = false; productImg.Visible = false; RequiredFileUploadValidator.Enabled = true; }
protected void butSubmit_Click(object sender, EventArgs e) { if (txtAdd.Text != "" && txtAmt.Text != "" && txtCD.Text != "" && txtCno.Text != "" && txtEadd.Text != "" && txtFname.Text != "" && txtLsp.Text != "" && txtQlf.Text != "" && txtSname.Text != "") { string Course_ID = ""; if (rbBCA.Checked == true) { Course_ID = "BCS001"; } if (rbBtech.Checked == true) { Course_ID = "BT002"; } if (rbMCA.Checked == true) { Course_ID = "MCS003"; } if (rbMtech.Checked == true) { Course_ID = "MT004"; } String sex = ""; if (rbMle.Checked == true) { sex = "Male"; } if (rbFml.Checked == true) { sex = "Male"; } String Status = ""; if (rbMd.Checked == true) { Status = "Married"; } if (rbUm.Checked == true) { Status = "Unmarried"; } string mode = ""; if (rbCash.Checked == true) { mode = "Cash"; } if (rbChk.Checked == true) { mode = "Check"; } if (rbdd.Checked == true) { mode = "DD"; } int RegNo; cmd.CommandText = "select max (Reg_No) from Student_Registration"; con.Open(); if (cmd.ExecuteScalar() == DBNull.Value) { RegNo = 1456; } else { RegNo = Convert.ToInt32(cmd.ExecuteScalar()) + 1; } int c = 0; if (FU.HasFile) { string s = FU.FileName; int i = s.Length; string sa = s.Substring((i - 4), 4); cmd.CommandText = "select count(Sname) from Student_Registration where Sname='" + txtSname.Text + "'"; if (con.State == ConnectionState.Closed) { con.Open(); } if (cmd.ExecuteScalar() == null) { c = 1; } else { c = Convert.ToInt32(cmd.ExecuteScalar()) + 1; } string s1 = txtSname.Text + Convert.ToString(c) + sa; FU.SaveAs(Server.MapPath("~/") + "/Students Photo/" + s1); cmd.Connection = con; cmd.CommandText = "Insert into Student_Registration values(" + RegNo + ",'" + Course_ID + "','" + txtSname.Text + "','" + (mm1.SelectedIndex + 1) + "/" + dd1.Text + "/" + yy1.Text + "','" + sex + "','" + Status + "'," + txtCno.Text + ",'" + txtQlf.Text + "','" + txtLsp.Text + "','" + txtFname.Text + "','" + (mm3.SelectedIndex + 1) + "/" + dd3.Text + "/" + yy3.Text + "','" + txtAdd.Text + "','" + txtEadd.Text + "','" + mode + "','" + txtCD.Text + "'," + txtAmt.Text + ",'" + (mm2.SelectedIndex + 1) + "/" + dd2.Text + "/" + yy2.Text + "','" + s1 + "')"; if (con.State == ConnectionState.Closed) { con.Open(); } cmd.ExecuteNonQuery(); con.Close(); clear(); Response.Redirect("StudentApp.aspx?Snm=" + txtSname.Text); txtSname.Text = ""; } } else { lblmsg.Text = "Any Field Cannot be Blank!"; } }