public IHttpActionResult PutUser(int id, User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //if (id != user.ID) //{ // return BadRequest(); //} db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!UserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public HttpResponseMessage UserRegister(string useremail, string username, string userphone, string userpassword, string userapartment, string userstreet, string usertown, string userstate, string userpincode, string usercountry) { if (CheckEmail(useremail)) { tblUser user = new tblUser() { useremail = useremail, username = username, userphone = userphone, userpassword = userpassword, userapartment = userapartment, userstreet = userstreet, usertown = usertown, userstate = userstate, userpincode = userpincode, usercountry = usercountry }; db.tblUsers.Add(user); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "success")); } return(Request.CreateResponse(HttpStatusCode.OK, "invalid")); }
public IHttpActionResult Putemployee(int id, employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employee.eid) { return(BadRequest()); } db.Entry(employee).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!employeeExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutTour(int id, Tour tour) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tour.ID) { return(BadRequest()); } db.Entry(tour).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TourExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult alltrue(int id) { var olddata = db5.register12.Where(a => a.id == id).FirstOrDefault(); olddata.status = "True"; db5.SaveChanges(); return(RedirectToAction("allow", "Admin")); }
public dynamic UpdatePassword(string email, string password) { //var query = from user in tblUser where user.email == email select user; var query = db.tblUsers.Find(email); query.userpassword = password; db.Entry(query).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Valid")); }
public HttpResponseMessage InsertCart(string useremail, int productid, int cartquantity) { tblCart cart = new tblCart() { useremail = useremail, productid = productid, cartquantity = cartquantity }; db.tblCarts.Add(cart); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Success")); }
private void buttonCustomerOrderAdd_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(1)) { try { projectEntities project = new projectEntities(); customerOrder cOrder = new customerOrder(); cOrder.CustomerID = Convert.ToInt32(textBoxCustomerID.Text); cOrder.OrderDate = orderDate.Value.Date; project.customerOrders.Add(cOrder); project.SaveChanges(); this.DisplayCustomerOrder(); MessageBox.Show("Recored Inserted.."); this.ClearTextBoxCO(); } catch (Exception ex) { MessageBox.Show("Recored Is Not Inserted..\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //this.ClearTextBoxCO(); } } else { MessageBox.Show("Please Enter Values. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public ActionResult UpdateData(HomeViewModel dbmodel) { try { projectEntities db = new projectEntities(); copiatt data = db.copiatts.SingleOrDefault(m => m.pi_id == dbmodel.pi_id); if (data != null) { data.at_id = dbmodel.at_id; data.course_id = dbmodel.course_id; data.target = float.Parse(dbmodel.target); db.SaveChanges(); } } catch (Exception ex) { throw ex; } //for message prompt TempData["flag"] = 1; TempData["MessageTitle"] = "Edit Data"; TempData["MessagePrompt"] = "Assessment Plan has been successfully updated"; return(RedirectToAction("AdminPage", "Home")); }
private void buttonCustomerOrderDelete_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(1) && !string.IsNullOrEmpty(textBoxCustomerID.Text)) { if (MessageBox.Show("Do You Want to Delete this Record", "Delete", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { projectEntities project = new projectEntities(); int customerOrderID = Convert.ToInt32(textBoxCustomerOrderID1.Text); // var = customerOrder var checkCustomerOrder = project.customerOrders.Find(customerOrderID); if (checkCustomerOrder != null) { project.customerOrders.Remove(checkCustomerOrder); project.SaveChanges(); this.DisplayCustomerOrder(); MessageBox.Show("Deletion Completed."); this.ClearTextBoxCO(); } } catch (Exception ex) { MessageBox.Show("Deletion Is Not Completed.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.ClearTextBoxCO(); } } } else { MessageBox.Show("Please Select a Row For Delete Operation."); this.ClearTextBoxCO(); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(1)) { try { projectEntities project = new projectEntities(); invoice invoice = new invoice(); invoice.InvoiceID = Convert.ToInt32(textBoxInvoiceID.Text); invoice.TotalPrice = Convert.ToDouble(textBoxTotalPrice.Text); invoice.TypeOfPayment = Convert.ToString(comboBoxTypeOfPayment.SelectedItem); invoice.PaymentDate = paymentDate.Value.Date; invoice.IsPaid = Convert.ToString(comboBoxIsPaid.SelectedItem); project.invoices.Add(invoice); project.SaveChanges(); this.DisplayData(); MessageBox.Show("Recored Inserted.."); this.ClearTextBox(); } catch (Exception ex) { MessageBox.Show("Recored Is Not Inserted..\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //this.ClearTextBoxCO(); } } else { MessageBox.Show("Please Enter Values. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonDelete_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(1)) { if (MessageBox.Show("Do You Want to Delete this Record", "Delete", MessageBoxButtons.YesNo) == DialogResult.Yes) { projectEntities project = new projectEntities(); int invoiceID = Convert.ToInt32(textBoxInvoiceID.Text); var checkInvoice = project.invoices.Find(invoiceID); if (checkInvoice != null) { project.invoices.Remove(checkInvoice); project.SaveChanges(); this.DisplayData(); MessageBox.Show("Record Is Updated."); this.ClearTextBox(); } } } else { MessageBox.Show("Please Select a Row For Delete Operation."); this.ClearTextBox(); } }
public dynamic ApproveRetailer(int retailerid, string retaileremail) { var retailer = db.tblRetailers.Find(retailerid); retailer.approved = 1; db.Entry(retailer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "Approved")); }
public ActionResult UpdatePass(AccountViewModel userModel) { try { projectEntities db = new projectEntities(); //Check if session still exists if (Session["accID"] == null) { return(RedirectToAction("Login", "Account")); } int id = (int)Session["accID"]; string pw = (string)Session["pw"]; //Check for the current session account id in db user data = db.users.SingleOrDefault(m => m.acc_id == id); if (data != null) { if (pw != userModel.password) { userModel.PassErrorMsg = "Incorrect Password, Try Again."; return(View("ChangePass", userModel)); } else if (pw == userModel.newpassword) { userModel.PassErrorMsg = "Password is the same, Try Again."; return(View("ChangePass", userModel)); } else { //Update user password in db and current session data.password = userModel.newpassword; db.SaveChanges(); Session["pw"] = userModel.newpassword; } } } catch (Exception ex) { throw ex; } //For message prompt purposes TempData["flag"] = 1; TempData["MessageTitle"] = "Change Password"; TempData["MessagePrompt"] = "Password has been successfully changed"; //Redirection Check if ((int)Session["type"] != 0) { return(RedirectToAction("MainPage", "Home")); } return(RedirectToAction("AdminPage", "Home")); }
public ActionResult register(register12 p, HttpPostedFileBase f) { string file2 = Path.Combine(Server.MapPath("~/img"), Path.GetFileName(f.FileName)); f.SaveAs(file2); p.pic = f.FileName; db.register12.Add(p); db.SaveChanges(); ModelState.Clear(); return(RedirectToAction("login", "home")); }
public HttpResponseMessage register(string retailername, string retaileremail, string retailerpassword) { try { tblRetailer retailer = new tblRetailer() { retailername = retailername, retaileremail = retaileremail, retailerpassword = retailerpassword, approved = 0 }; db.tblRetailers.Add(retailer); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, "valid")); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.OK, "invalid")); } }
public ActionResult Fee_status(Payment q, HttpPostedFileBase g) { string w = Path.Combine(Server.MapPath("~/pay"), Path.GetFileName(g.FileName)); g.SaveAs(w); q.upload = g.FileName; dbp.Payments.Add(q); dbp.SaveChanges(); ModelState.Clear(); return(View()); }
private void buttonBookOrderDelete_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(3)) { if (MessageBox.Show("Do You Want to Delete this Record", "Delete", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { projectEntities project = new projectEntities(); var checkBookOrder = project.bookOrders.Where(x => x.CustomerOrderID == cOrderIDUpdate && x.BookID == bookIDUpdate && x.OrderQuantity == orderQuantityUpdate).SingleOrDefault(); if (checkBookOrder != null) { project.bookOrders.Remove(checkBookOrder); // add Book quantity to QOH(book) when delete. var checkBook = project.books.Find(bookIDUpdate); checkBook.QOH = checkBook.QOH + orderQuantityUpdate; // remove price of that book order in invoice table var checkInvoice = project.invoices.Find(cOrderIDUpdate); checkInvoice.TotalPrice = checkInvoice.TotalPrice - (checkBook.UnitPrice * orderQuantityUpdate); project.SaveChanges(); MessageBox.Show("Deletion Completed."); this.DisplayBookOrder(); this.ClearTextBoxBO(); } else { MessageBox.Show("Deletion Is Not Completed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.ClearTextBoxBO(); } } catch (Exception ex) { MessageBox.Show("Deletion Is Not Completed.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.ClearTextBoxCO(); } } } else { MessageBox.Show("Please Select a Row For Delete Operation."); this.ClearTextBoxCO(); } }
//Update private void buttonUpdate_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(1) && !string.IsNullOrEmpty(textBoxBookID.Text)) { if (MessageBox.Show("Do You Want to Update this Record", "Update", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { projectEntities project = new projectEntities(); int bookid = Convert.ToInt32(textBoxBookID.Text); var checkBookID = project.books.Find(bookid); if (checkBookID != null) { checkBookID.ISBN = textBoxISBN.Text; checkBookID.Title = textBoxTitle.Text; checkBookID.UnitPrice = Convert.ToDouble(textBoxPrice.Text); checkBookID.YearPublished = publishYear.Value.Date; checkBookID.QOH = Convert.ToInt32(textBoxQoh.Text); checkBookID.CategoryID = Convert.ToInt32(textBoxCategoryID.Text); checkBookID.AuthorID = Convert.ToInt32(textBoxAuthorID.Text); checkBookID.PublishID = Convert.ToInt32(textBoxPublishID.Text); project.SaveChanges(); this.DisplayBookInformation(); MessageBox.Show("Record Is Updated."); this.ClearTextBox(); } } catch (Exception ex) { MessageBox.Show("Recored Is Not Updated..\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Please Select a Row For Update Operation."); } }
public ActionResult AddData(HomeViewModel model) { try { projectEntities db = new projectEntities(); user User = new user(); //Get all inputted information and save to db User.type_id = model.SelectedType; User.FName = model.FName; User.MName = model.MName; User.LName = model.LName; User.username = model.username; User.password = model.password; db.users.Add(User); db.SaveChanges(); string filepath = Server.MapPath("~/UserFiles/" + User.acc_id); if (Directory.Exists(filepath)) { } else { //Add file folder for new user DirectoryInfo di = Directory.CreateDirectory(filepath); } } catch (Exception ex) { throw ex; } //for message prompt purposes TempData["flag"] = 1; TempData["MessageTitle"] = "Create Account"; TempData["MessagePrompt"] = "Account has been created"; return(RedirectToAction("AdminPage")); }
private void buttonUpdate_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(1)) { if (MessageBox.Show("Do You Want to Update this Record", "Update", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { projectEntities project = new projectEntities(); int invoiceID = Convert.ToInt32(textBoxInvoiceID.Text); var checkInvoice = project.invoices.Find(invoiceID); if (checkInvoice != null) { //checkInvoice.TotalPrice = Convert.ToDouble(textBoxTotalPrice.Text); checkInvoice.PaymentDate = paymentDate.Value.Date; checkInvoice.TypeOfPayment = comboBoxTypeOfPayment.SelectedItem.ToString(); checkInvoice.IsPaid = comboBoxIsPaid.SelectedItem.ToString(); project.SaveChanges(); this.DisplayData(); MessageBox.Show("Record Is Updated."); this.ClearTextBox(); } } catch (Exception ex) { MessageBox.Show("Recored Is Not Updated..\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //this.ClearTextBoxCO(); } } } else { MessageBox.Show("Please Select a Row For Update Operation."); } }
//Delete user in db as well as send json to signal js to remove row public JsonResult DeleteData(int acc_id) { projectEntities db = new projectEntities(); bool result = false; user data = db.users.SingleOrDefault(x => x.acc_id == acc_id); if (data != null) { db.users.Remove(data); db.SaveChanges(); result = true; string filepath = Server.MapPath("~/UserFiles/" + acc_id); if (Directory.Exists(filepath)) { DirectoryInfo di = new DirectoryInfo(filepath); di.Delete(); } } return(Json(result, JsonRequestBehavior.AllowGet)); }
//Add private void buttonAdd_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(1)) { try { projectEntities project = new projectEntities(); book book = new book(); book.ISBN = textBoxISBN.Text; book.Title = textBoxTitle.Text; book.UnitPrice = Convert.ToDouble(textBoxPrice.Text); book.YearPublished = publishYear.Value.Date; book.QOH = Convert.ToInt32(textBoxQoh.Text); book.AuthorID = Convert.ToInt32(textBoxAuthorID.Text); book.PublishID = Convert.ToInt32(textBoxPublishID.Text); book.CategoryID = Convert.ToInt32(textBoxCategoryID.Text); project.books.Add(book); project.SaveChanges(); this.DisplayBookInformation(); MessageBox.Show("Recored Inserted.."); this.ClearTextBox(); } catch (Exception ex) { MessageBox.Show("Recored Is Not Inserted..\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.ClearTextBox(); } } else { MessageBox.Show("Please Enter Values. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public HttpResponseMessage UploadImage() { string imageName = null; var httpRequest = HttpContext.Current.Request; //Upload Image var postedFile = httpRequest.Files["Image"]; //Create custom filename imageName = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-"); imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName); var filePath = HttpContext.Current.Server.MapPath("~/Image/" + imageName); postedFile.SaveAs(filePath); //Save to DB using (projectEntities db = new projectEntities()) { tblProduct tblProduct = new tblProduct() { retailerid = Convert.ToInt32(httpRequest["RetailerId"]), productname = httpRequest["ProductName"], productdescription = httpRequest["ProductDescription"], productbrand = httpRequest["ProductBrand"], productquantity = Convert.ToInt32(httpRequest["ProductQuantity"]), productprice = Convert.ToInt32(httpRequest["ProductPrice"]), categoryid = Convert.ToInt32(httpRequest["CategoryId"]), productimage1 = imageName, }; db.tblProducts.Add(tblProduct); db.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.Created)); }
public ActionResult APost(FileViewModels model) { projectEntities db = new projectEntities(); process pro = new process(); Excel.Application xlApp; Excel.Workbook xlWorkBook1; Excel.Worksheet xlWorkSheet1; Excel.Range range; int str; int rCnt; int cCnt; int rw = 0; int cl = 0; xlApp = new Excel.Application(); if (xlApp == null) { TempData["flag"] = 1; TempData["MessageTitle"] = "Generate Plan"; TempData["MessagePrompt"] = "Error occured, please check Excel Software"; return(RedirectToAction("MainPage", "Home")); } int qtr_ref = model.quarter; int sy_ref = model.year; string[] so = ListSO(); string[] course = ListCourse(); string[] pi = ListPI(); string[] asstool = ListAT(); float[] studtarget = ListTarget(); int[] atid = ListATID(); int studpass = 0; int studtot = 0; int studpassall = 0; int studtotall = 0; double studpassave; double studpassallave = 0; int ctr; int qtr = 1; int sy = 1; int qtr1 = 1; int qtr2 = 1; int qtr3 = 1; int qtr4 = 1; int sy1 = 1516; int sy2 = 1516; int sy3 = 1516; int sy4 = 1516; List <int> studpass1 = new List <int>(); List <int> studtot1 = new List <int>(); List <int> studpassall1 = new List <int>(); List <int> studtotall1 = new List <int>(); List <double> studpassave1 = new List <double>(); List <double> studpassallave1 = new List <double>(); List <double> result = new List <double>(); pro.quarter = model.quarter; pro.year = model.year; pro.copiatt_id = 1; db.processes.Add(pro); db.SaveChanges(); //Generate File Location if (Session["accID"] == null) { return(RedirectToAction("Login", "Account")); } int accid = (int)Session["accID"]; string filepath = Server.MapPath("~/Uploads"); string filepath1 = Server.MapPath("~/UserFiles/" + accid + "/AssessmentPlan_" + accid + "_" + pro.pid + ".xlsx"); for (int i = 0; i < 24; i++) { ctr = 0; do { studpass = 0; studtot = 0; if (ctr == 0) { qtr = qtr_ref; sy = sy_ref; qtr1 = qtr; sy1 = sy; } else if (ctr == 1) { qtr2 = qtr1; sy2 = sy1; if (qtr1 == 4) { qtr2 = 1; qtr = qtr2; sy2 += 101; sy = sy2; } else { qtr2++; qtr = qtr2; } } else if (ctr == 2) { qtr3 = qtr2; sy3 = sy2; if (qtr3 == 4) { qtr3 = 1; qtr = qtr3; sy3 += 101; sy = sy3; } else { qtr3++; qtr = qtr3; } } else if (ctr == 3) { qtr4 = qtr3; sy4 = sy3; if (qtr4 == 4) { qtr4 = 1; qtr = qtr4; sy4 += 101; sy = sy4; } else { qtr4++; qtr = qtr4; } } List <int> grades = new List <int>(); string[] files = Directory.GetFiles(filepath, qtr + "QSY" + sy + "_" + course[i] + "_*.xlsx"); foreach (string file in files) { xlWorkBook1 = xlApp.Workbooks.Open(file, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet1 = (Excel.Worksheet)xlWorkBook1.Worksheets.get_Item(1); range = xlWorkSheet1.UsedRange; rw = range.Rows.Count; cl = range.Columns.Count; for (cCnt = 1; cCnt <= cl; cCnt++) { if (xlWorkSheet1.Cells[1, cCnt].Value2 != null) { string columnName = xlWorkSheet1.Cells[1, cCnt].Value2; ViewBag.id = atid[i]; string[] atcase = ATcase(); for (int j = 0; j < atcase.Length; j++) { string match = atcase[j]; if (Regex.IsMatch(columnName, match, RegexOptions.IgnoreCase | RegexOptions.Singleline)) { str = 0; for (rCnt = 2; rCnt <= rw; rCnt++) { str = (int)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; grades.Add(str); } break; } } } } xlWorkBook1.Close(true, null, null); Marshal.ReleaseComObject(xlWorkSheet1); Marshal.ReleaseComObject(xlWorkBook1); } int a = 0; foreach (float val in grades) { if (val >= 70) { studpass++; } studtot++; a++; } studpass1.Add(studpass); studtot1.Add(studtot); studpassall += studpass; studtotall += studtot; studpassave = ((double)studpass / (double)studtot) * 100; studpassave1.Add(studpassave); if (ctr == 3) { studpassall1.Add(studpassall); studtotall1.Add(studtotall); studpassallave = ((double)studpassall / (double)studtotall) * 100; studpassallave1.Add(studpassallave); result.Add(studpassallave); studpassall = 0; studtotall = 0; } ctr++; } while (ctr < 4); } //Generate Assessment Plan Excel.Workbook xlWorkBook2; Excel.Worksheet xlWorkSheet2; object misValue = System.Reflection.Missing.Value; xlWorkBook2 = xlApp.Workbooks.Add(misValue); xlWorkSheet2 = (Excel.Worksheet)xlWorkBook2.Worksheets.get_Item(1); Excel.Range last = xlWorkSheet2.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing); range = xlWorkSheet2.get_Range("A1", last); range.Style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; range.Style.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; range.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; range.Style.WrapText = true; xlWorkSheet2.Columns[1].ColumnWidth = 18; range = xlWorkSheet2.get_Range("A1", "BU1"); range.Merge(misValue); range.Value2 = "STUDENT OUTCOMES AND EVALUATION PLAN FOR COMPUTER ENGINEERING"; //Student Outcomes xlWorkSheet2.Rows[2].RowHeight = 70; xlWorkSheet2.Cells[2, 1] = "STUDENT OUTCOMES"; int index = 0; for (int i = 2; i <= 68; i += 6) { int j = i; Excel.Range r1 = xlWorkSheet2.Cells[2, j]; j += 5; Excel.Range r2 = xlWorkSheet2.Cells[2, j]; range = xlWorkSheet2.get_Range(r1, r2); range.Merge(misValue); range.Value2 = so[index++]; } range = xlWorkSheet2.get_Range("A2", "BU2"); range.Interior.Color = Color.PeachPuff; //Performance Indicators xlWorkSheet2.Rows[3].RowHeight = 70; xlWorkSheet2.Cells[3, 1] = "Performance Indicators"; index = 0; for (int i = 2; i <= 71; i += 3) { int j = i; Excel.Range r1 = xlWorkSheet2.Cells[3, j++]; Excel.Range r2 = xlWorkSheet2.Cells[3, ++j]; range = xlWorkSheet2.get_Range(r1, r2); range.Merge(misValue); range.Value2 = pi[index++]; } range = xlWorkSheet2.get_Range("A3", "BU3"); range.Interior.Color = Color.Yellow; //Course xlWorkSheet2.Cells[4, 1] = "Course"; index = 0; for (int i = 2; i <= 71; i += 3) { int j = i; Excel.Range r1 = xlWorkSheet2.Cells[4, j++]; Excel.Range r2 = xlWorkSheet2.Cells[4, ++j]; range = xlWorkSheet2.get_Range(r1, r2); range.Merge(misValue); range.Value2 = course[index++]; } range = xlWorkSheet2.get_Range("A4", "BU4"); range.Interior.Color = Color.LimeGreen; //Assessment Tool xlWorkSheet2.Rows[5].RowHeight = 30; xlWorkSheet2.Cells[5, 1] = "Assessment Tool"; index = 0; for (int i = 2; i <= 71; i += 3) { int j = i; Excel.Range r1 = xlWorkSheet2.Cells[5, j++]; Excel.Range r2 = xlWorkSheet2.Cells[5, ++j]; range = xlWorkSheet2.get_Range(r1, r2); range.Merge(misValue); range.Value2 = asstool[index++]; } range = xlWorkSheet2.get_Range("A5", "BU5"); range.Interior.Color = Color.Orange; //Assessment Targets and Results xlWorkSheet2.Cells[6, 1] = "Assessment Targets and Results"; for (int i = 2; i <= 71; i += 3) { int j = i; xlWorkSheet2.Cells[6, i] = "Target"; Excel.Range r1 = xlWorkSheet2.Cells[6, ++j]; Excel.Range r2 = xlWorkSheet2.Cells[6, ++j]; range = xlWorkSheet2.get_Range(r1, r2); range.Merge(misValue); range.Value2 = "Results"; } range = xlWorkSheet2.get_Range("A6", "BU6"); range.Interior.Color = Color.Aqua; //Periods xlWorkSheet2.Cells[7, 1] = "Period: Q" + qtr1 + " SY" + sy1; xlWorkSheet2.Cells[8, 1] = "Period: Q" + qtr2 + " SY" + sy2; xlWorkSheet2.Cells[9, 1] = "Period: Q" + qtr3 + " SY" + sy3; xlWorkSheet2.Cells[10, 1] = "Period: Q" + qtr4 + " SY" + sy4; xlWorkSheet2.Cells[11, 1] = "Overall Results (Q" + qtr1 + " SY" + sy1 + " to Q" + qtr4 + " SY" + sy4; range = xlWorkSheet2.get_Range("A11", "BU11"); range.Interior.Color = Color.HotPink; int b = 0; for (int i = 2; i <= 71; i += 3) { Excel.Range r1 = xlWorkSheet2.Cells[7, i]; Excel.Range r2 = xlWorkSheet2.Cells[11, i]; range = xlWorkSheet2.get_Range(r1, r2); range.Merge(misValue); range.Value2 = studtarget[b] + "% of students should obtain a rating of at least 3.5"; b++; } //computation int index1 = 0; int index2 = 0; for (int i = 3; i <= 72; i += 3) { for (int j = 7; j <= 11; j++) { if (j == 11) { int l = i; xlWorkSheet2.Cells[j, l] = studpassall1[index2] + " out of " + studtotall1[index2]; xlWorkSheet2.Cells[j, ++l] = studpassallave1[index2] + "%"; index2++; } else { int l = i; xlWorkSheet2.Cells[j, l] = studpass1[index1] + " of " + studtot1[index1] + " students enrolled"; xlWorkSheet2.Cells[j, ++l] = studpassave1[index1] + "%"; index1++; } } } //Evaluation, Recommendation and Effectivity xlWorkSheet2.Cells[12, 1] = "Evaluation"; xlWorkSheet2.Cells[12, 1].Interior.Color = Color.PaleGreen; xlWorkSheet2.Rows[13].RowHeight = 90; xlWorkSheet2.Cells[13, 1] = "Recommendation"; xlWorkSheet2.Cells[14, 1] = "Effectivity"; range = xlWorkSheet2.get_Range("A14", "BU14"); range.Interior.Color = Color.Beige; index = 0; int col = 2; if (qtr4 == 4) { qtr4 = 1; sy4 += 101; } else { qtr4++; } int c = 0; foreach (float res in result) { int col1 = col; Excel.Range r1 = xlWorkSheet2.Cells[12, col1++]; Excel.Range r2 = xlWorkSheet2.Cells[12, ++col1]; range = xlWorkSheet2.get_Range(r1, r2); range.Merge(misValue); col1 = col; Excel.Range r11 = xlWorkSheet2.Cells[13, col1++]; Excel.Range r21 = xlWorkSheet2.Cells[13, ++col1]; if (res >= studtarget[c]) { range.Value2 = "Target Achieved"; range.Interior.Color = Color.PaleGreen; range = xlWorkSheet2.get_Range(r11, r21); range.Merge(misValue); range.Value2 = "Retain Performance Indicator, Assessment Tool and Targets for the course " + course[index++]; } else if (res < studtarget[c]) { range.Value2 = "Target Not Achieved"; range.Interior.Color = Color.Red; range = xlWorkSheet2.get_Range(r11, r21); range.Merge(misValue); range.Value2 = "Modify Performance Indicator, Assessment Tool and Targets for the course " + course[index++]; } else { range.Value2 = "Evaluation N/A"; range.Interior.Color = Color.LightGray; range = xlWorkSheet2.get_Range(r11, r21); range.Merge(misValue); range.Value2 = "Recommendation for the course " + course[index++] + " N/A"; } col1 = col; Excel.Range r12 = xlWorkSheet2.Cells[14, col1++]; Excel.Range r22 = xlWorkSheet2.Cells[14, ++col1]; range = xlWorkSheet2.get_Range(r12, r22); range.Merge(misValue); range.Value2 = qtr4 + "Q AY " + sy4; col += 3; c++; } range = xlWorkSheet2.get_Range("A1", "BU14"); range.Borders.LineStyle = Excel.XlLineStyle.xlContinuous; range.Borders.Weight = Excel.XlBorderWeight.xlThick; xlWorkBook2.SaveAs(filepath1, Excel.XlFileFormat.xlOpenXMLWorkbook, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook2.Close(true, misValue, misValue); xlApp.Quit(); Marshal.ReleaseComObject(xlWorkSheet2); Marshal.ReleaseComObject(xlWorkBook2); Marshal.ReleaseComObject(xlApp); //Update outcome table DateTime dt = DateTime.Now; outcome oc = new outcome(); oc.pid = pro.pid; oc.acc_id = accid; oc.filename = "AssessmentPlan_" + accid + "_" + pro.pid + ".xlsx"; oc.cdate = dt; db.outcomes.Add(oc); db.SaveChanges(); //Delete Files in Upload Folder System.IO.DirectoryInfo di = new DirectoryInfo(filepath); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } TempData["flag"] = 1; TempData["MessageTitle"] = "Generate Plan"; TempData["MessagePrompt"] = "Assessment Plan has been created, check Downloads"; if ((int)Session["type"] != 0) { return(RedirectToAction("MainPage", "Home")); } return(RedirectToAction("AdminPage", "Home")); }
private void buttonBookOrderAdd_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(3)) { try { projectEntities project = new projectEntities(); bookOrder bOrder = new bookOrder(); bOrder.CustomerOrderID = Convert.ToInt32(textBoxCustomerOrderID2.Text); bOrder.BookID = Convert.ToInt32(textBoxBookID.Text); bOrder.OrderQuantity = Convert.ToInt32(textBoxOrderQuantity.Text); int checkBookID = Convert.ToInt32(textBoxBookID.Text); int customerOrderID = Convert.ToInt32(textBoxCustomerOrderID2.Text); // Find Book var checkBook = project.books.Find(checkBookID); if (Convert.ToInt32(textBoxOrderQuantity.Text) <= checkBook.QOH) { project.bookOrders.Add(bOrder); // Update the book qoh int newBookQOH = checkBook.QOH - Convert.ToInt32(textBoxOrderQuantity.Text); checkBook.QOH = newBookQOH; // Check in invoice table id is exist or not double unitPrice = checkBook.UnitPrice; int orderQuantity = Convert.ToInt32(textBoxOrderQuantity.Text); if (project.invoices.Any(x => x.InvoiceID == customerOrderID)) { // update to invoice table var updateInvoice = project.invoices.Find(customerOrderID); double oldTotalPrice = updateInvoice.TotalPrice; double newTotalPrice = oldTotalPrice + (unitPrice * orderQuantity); MessageBox.Show(" newTotalPrice " + newTotalPrice + " customerOrderID " + customerOrderID); updateInvoice.TotalPrice = newTotalPrice; } else { // insert to invoice table invoice invoice = new invoice(); invoice.InvoiceID = customerOrderID; invoice.TotalPrice = (unitPrice * orderQuantity); invoice.TypeOfPayment = "None"; //DateTime date = new DateTime(1111, 11, 11); //invoice.PaymentDate = date; invoice.IsPaid = "n"; project.invoices.Add(invoice); } project.SaveChanges(); MessageBox.Show("Recored Inserted.."); this.DisplayBookOrder(); this.ClearTextBoxBO(); } else { string msg = string.Format(" We only have {0} books for \n " + " Book Id = {1} \n " + " Book Name = {2} ", checkBook.QOH, Convert.ToInt32(textBoxBookID.Text), checkBook.Title); MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Recored Is Not Inserted..\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //this.ClearTextBoxCO(); } } else { MessageBox.Show("Please Enter Values. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonBookOrderUpdate_Click(object sender, EventArgs e) { if (ValidateEmptyTextBox(3) && !string.IsNullOrEmpty(textBoxCustomerOrderID2.Text)) { if (MessageBox.Show("Do You Want to Update this Record", "Update", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { projectEntities project = new projectEntities(); var checkBookOrder = project.bookOrders.Where(x => x.CustomerOrderID == cOrderIDUpdate && x.BookID == bookIDUpdate && x.OrderQuantity == orderQuantityUpdate).SingleOrDefault(); if (checkBookOrder != null) { // check Book var checkBook = project.books.Find(bookIDUpdate); // old(book) order(bookorder) new (book) // 150 100 50 // 1) 50 80 70 // 2) 50 110 40 int oldBookQOH = checkBook.QOH; int oldBookOrderQuantity = orderQuantityUpdate; int newBookOrderQuantity = Convert.ToInt32(textBoxOrderQuantity.Text); // update to invoice table var updateInvoice = project.invoices.Find(cOrderIDUpdate); //double unitPrice = checkBook.UnitPrice; double oldtotalPrice = checkBook.UnitPrice * oldBookOrderQuantity; double newtotalPrice = checkBook.UnitPrice * newBookOrderQuantity; if (newBookOrderQuantity > oldBookOrderQuantity) { // Book QOH int newBookQOH = oldBookQOH - (newBookOrderQuantity - oldBookOrderQuantity); checkBook.QOH = newBookQOH; // Invoice TotalPrice double totalPrice = updateInvoice.TotalPrice + (newtotalPrice - oldtotalPrice); updateInvoice.TotalPrice = totalPrice; MessageBox.Show("more " + totalPrice); } else if (newBookOrderQuantity < oldBookOrderQuantity) { // Book QOH int newBookQOH = oldBookQOH + (oldBookOrderQuantity - newBookOrderQuantity); checkBook.QOH = newBookQOH; // Invoice TotalPrice double totalPrice = updateInvoice.TotalPrice - (oldtotalPrice - newtotalPrice); updateInvoice.TotalPrice = totalPrice; MessageBox.Show("less " + totalPrice); } string query = string.Format(" Update bookOrder " + " set CustomerOrderID = {0} , BookID = {1} , OrderQuantity = {2} where " + " CustomerOrderID = {3} and BookID = {4} and OrderQuantity = {5} ", Convert.ToInt32(textBoxCustomerOrderID2.Text), Convert.ToInt32(textBoxBookID.Text), newBookOrderQuantity, cOrderIDUpdate, bookIDUpdate, orderQuantityUpdate); project.Database.ExecuteSqlCommand(query); project.SaveChanges(); MessageBox.Show("Record Is Updated."); this.DisplayBookOrder(); this.ClearTextBoxBO(); } } catch (Exception ex) { MessageBox.Show("Recored Is Not Updated.. \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //this.ClearTextBoxCO(); } } } else { MessageBox.Show("Please Select a Row For Update Operation."); } }
public void Save() { db.SaveChanges(); }