/************************************Submit Requisition*************************************/ protected void Submit_Click(object sender, EventArgs e) { string name = Session["loginID"].ToString(); SA45_Team09_LogicUEntities m = new DBEntities().getDBInstance(); ///should use DAO string deptID = m.DeptStaffs.Where(x => x.staffID == name).Select(y => y.deptID).First().ToString();//supposed to be in DepartmentDAO List <cart> lc = new List <cart>(); lc = (List <cart>)Session["cart"]; if (lc.Count > 0) { Dictionary <string, int> dict = new Dictionary <string, int>(); int judge = 0; int num = 0; foreach (Control i in cartRepeater.Items) //get Quantity { LinkButton deletebtn = i.FindControl("cart_deleteButton") as LinkButton; //get itemID TextBox cartqty = i.FindControl("cart_qtyTextBox") as TextBox; //get quantity if (cartqty.Text.Trim() == "") { judge = 1; break; } try { lc[num].Qty = Int32.Parse(cartqty.Text.ToString()); } catch { judge = 1; break; } if ((lc[num].Qty % 1 != 0) || (lc[num].Qty <= 0)) { judge = 1; break; } dict.Add(deletebtn.CommandArgument.ToString(), Int32.Parse(cartqty.Text.ToString())); num++; } if (judge == 0) { RequisitionDAO rdao = new RequisitionDAO(); rdao.addRequisition(name, deptID, dict); lc = new List <cart>();//clear the cart session Session["cart"] = lc; //send email and notification to head string headID = m.Departments.Where(x => x.deptID == deptID).Select(x => x.headStaffID).ToList().First(); string headName = m.DeptStaffs.Where(x => x.staffID == headID).Select(x => x.staffName).ToList().First(); string staffName = Session["loginName"].ToString(); string staffID = Session["loginID"].ToString(); NotificationDAO nDAO = new NotificationDAO(); nDAO.addDeptNotification(headID, staffName + " send a new requisition!", DateTime.Now); Email email = new Email(); email.sendNewReqEmailToHead(staffName, headName); HttpContext.Current.Response.Redirect("Emp_MyRequisition.aspx"); } else { ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>win.alert('Notice', 'Input must be integer!');</script>"); } } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage2", "alert('Nothing in cart')", true); return; } }