protected void SendPrescription_Click(object sender, EventArgs e) { UserIdO.Text = ""; MedicineNameO.Text = ""; MedicineCountO.Text = ""; Doctor d = (Doctor)Session["doctor"]; bool isValid = true; if (MedicineNameDDL.SelectedIndex == 0) { isValid = false; MedicineNameO.Text = "לא בחרת תרופה"; } if (UserNameDDL.SelectedIndex == 0) { isValid = false; UserIdO.Text = "לא בחרת לקוח"; } if (MedicineCountTB.Text != "" && Validation.IsHouseNumberValid(MedicineCountTB.Text)) { if (Convert.ToInt32(MedicineCountTB.Text) <= 0) { isValid = false; MedicineCountO.Text = "כמות לא תקינה"; } } else { isValid = false; MedicineCountO.Text = "כמות לא תקינה"; } if (isValid) { int count = Convert.ToInt32(MedicineCountTB.Text); Pharmcy.PharmcyWS webser = new Pharmcy.PharmcyWS(); Prescription newp = new Prescription(); PrescriptioService ps = new PrescriptioService(); newp.CPrescriptionMedicineId = Convert.ToInt32(MedicineNameDDL.SelectedValue); DataSet ds = ps.IsPresAlreadyExist(newp.CPrescriptionMedicineId); if (ds.Tables[0].Rows.Count != 0) { int currentCount = Convert.ToInt32(ds.Tables[0].Rows[0]["PrescriptionMedicineCount"].ToString()); ps.UpdatePresMedCount(newp.CPrescriptionMedicineId, (currentCount + count)); ResetData_Click(sender, e); Response.Write("<script>alert('המרשם נשלח בהצלחה')</script>"); return; } newp.CPrescriptionUserId = UserNameDDL.SelectedValue; newp.CPrescriptionDoctorId = d.CDoctorId; newp.CPrescriptionDate = DateTime.Now; newp.CPrescriptionMedicineCount = count; newp.CPrescriptionMedicineName = MedicineNameDDL.SelectedItem.Text; newp.CPrescriptionMedicineCatagory = webser.GetMedicineCatagory(newp.CPrescriptionMedicineId); ps.InsertPrescriptionToDataBase(newp); ResetData_Click(sender, e); //say the prescription send succesfully Response.Write("<script>alert('המרשם נשלח בהצלחה')</script>"); } }
protected void SearchReasultGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "AddMedicine") { //check if the user is logged in, if not get him a message about it and redirect him to the regestrataion page User s = (User)Session["user"]; if (s == null) { Response.Write("<script>alert('על מנת לרכוש מוצרים עליך להיות לקוח רשום')</script>"); Response.Write("<script>window.open('http://localhost:49675/GuestHome.aspx','_blank');</script>"); return; } //get the shopping bag myShoppingBag = (ShoppingBag)Session["myShoppingBag"]; int rowNumber = Convert.ToInt32(e.CommandArgument); //create the medicineInBag var Pharmcy.PharmcyWS webser = new Pharmcy.PharmcyWS(); MedicineInBag MIB = new MedicineInBag(); MIB.CMedicineName = SearchReasultGrid.Rows[rowNumber].Cells[1].Text; MIB.CMedicineId = SearchReasultGrid.Rows[rowNumber].Cells[0].Text; MIB.CMedicinePrice = Convert.ToInt32(SearchReasultGrid.Rows[rowNumber].Cells[2].Text); MIB.CMedicineInBagMedicinePrice = Convert.ToInt32(MIB.CMedicinePrice); MIB.CMedicineNeedPrescription = Convert.ToBoolean(SearchReasultGrid.Rows[rowNumber].Cells[6].Text); MIB.CMedicineStock = Convert.ToInt32(SearchReasultGrid.Rows[rowNumber].Cells[3].Text); //same in MedicineCatagory MIB.CMedicineProducer = webser.GetMedicineProducer(Convert.ToInt32(MIB.CMedicineId)); MIB.CMedicineCatagory = webser.GetMedicineCatagory(Convert.ToInt32(MIB.CMedicineId)); DataSet temp = webser.GetMedicineCataAndProName(MIB.CMedicineCatagory, MIB.CMedicineProducer); MIB.CMedicineInBagCatagoryName = temp.Tables[0].Rows[0]["MedicineCatagoryName"].ToString(); MIB.CMedicineInBagProducerName = temp.Tables[0].Rows[0]["MedicineProducerName"].ToString(); /////////////////////////////////////////////////////////////////////////////////// //check count of medicine //because we didnt change the current stock of the medicine we need to check if there is //enough from this medicine to buy int countOfMedicine = myShoppingBag.GetMedicineCount(Convert.ToInt32(MIB.CMedicineId)); User u = (User)Session["user"]; if (MIB.CMedicineStock - countOfMedicine <= 0) { Response.Write("<script>alert('אין מספיק תרופות במלאי')</script>"); return; } /////////////////////////////////////////////////////////////////////////////////// //check prescription int MedIdNumber = Convert.ToInt32(MIB.CMedicineId); //still dont change the current stock of medicine if (MIB.CMedicineNeedPrescription) { PrescriptioService ps = new PrescriptioService(); DataSet ds = ps.GetPrescriptionByMedicineId(MedIdNumber, u.CUserId); if (ds.Tables[0].Rows.Count == 0) { Response.Write("<script>alert('תרופה זאת צריכה מרשם')</script>"); return; } else { //לבדוק אם הוא באמת הכניס אותה כמות //אם הוא הכניס אותה כמות אז הכל בסדר //צריך לזכור לבטל את המרשם ברגע שהקנייה מתבצעת //אם הכמות לא שווה אז ליידע את הלקוח שהוא צריך לבדוק כמה כדורים נתנו לו //אפשרות לחשוף קישור בדף לעמוד של המרשמים כדי שיוכל להסתכל //או שאפשר להגיד למשתמש כמה כדורים הוא יכול לקחת(מעדיף שלא נשמע קצת מוזר) presList = (List <DataSet>)Session["presList"]; if (presList != null) { foreach (DataSet d in presList) { if (ds.Tables[0].Rows[0]["PrescriptionId"].ToString() == d.Tables[0].Rows[0]["PrescriptionId"].ToString()) { Response.Write("<script>alert('מרשם זה כבר שומש')</script>"); return; } } } presList.Add(ds); Session["presList"] = presList; int count = Convert.ToInt32(ds.Tables[0].Rows[0]["PrescriptionMedicineCount"].ToString()); MIB.CMedicineInBagMedicineCount = count; } } else { MIB.CMedicineInBagMedicineCount = 1; } myShoppingBag.AddMedicine(MIB); Session["myShoppingBag"] = myShoppingBag; Response.Write("<script>alert('המוצר הוסף לסל')</script>"); CheckoutButton.Visible = true; SeeShoppingBag.Visible = true; } }