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 ShowPrescription_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeletePrescription") { int rowNumber = Convert.ToInt32(e.CommandArgument); int presId = Convert.ToInt32(ShowPrescription.Rows[rowNumber].Cells[0].Text); PrescriptioService ps = new PrescriptioService(); ps.DeletePrescription(presId); SortDDL_SelectedIndexChanged(sender, e); } }
protected void SortDDL_SelectedIndexChanged(object sender, EventArgs e) { //init the visible of the gridview and the close button ClosePrescription.Visible = false; ShowPrescription.Visible = false; int x = SortDDL.SelectedIndex; DataSet ds; PrescriptioService ps = new PrescriptioService(); //create the SQL query string whereclout = " WHERE DoctorId=PrescriptionDoctorId and UserId=PrescriptionUserId"; switch (x) { case 1: { whereclout += " ORDER BY PrescriptionDoctorId"; break; } case 2: { whereclout += " ORDER BY PrescriptionUserId"; break; } case 3: { whereclout += " ORDER BY PrescriptionMedicineId"; break; } case 4: { whereclout += " ORDER BY PrescriptionDate"; break; } } ds = ps.SortPrescriptionManager(whereclout); if (ds.Tables[0].Rows.Count != 0) { ClosePrescription.Visible = true; ShowPrescription.Visible = true; ShowPrescription.DataSource = ds; ShowPrescription.DataBind(); } else { Response.Write("<script>alert('לא נמצאו מרשמים')</script>"); } }
protected void ShowPrescriptionGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "UsePrescription") { int rowNumber = Convert.ToInt32(e.CommandArgument); int presId = Convert.ToInt32(ShowPrescriptionGrid.Rows[rowNumber].Cells[0].Text); int medId = Convert.ToInt32(ShowPrescriptionGrid.Rows[rowNumber].Cells[3].Text); int medCount = Convert.ToInt32(ShowPrescriptionGrid.Rows[rowNumber].Cells[5].Text); Pharmcy.PharmcyWS webser = new Pharmcy.PharmcyWS(); int medStock = webser.GetMedicineStock(medId); if (medCount > medStock) { Response.Write("<script>alert('אין מספיק תרופות במלאי')</script>"); return; } webser.UpdateMedCount(medStock - medCount, medId); PrescriptioService ps = new PrescriptioService(); //get the total price of the prescription int medPrice = webser.GetMedicinePrice(medId); int totalPrice = medPrice * medCount; ps.DeletePrescription(presId); Response.Write("<script>alert('המרשם מומש בהצלחה, עלות ההזמנה היא: " + totalPrice + " שקלים')</script>"); SortPrescription_SelectedIndexChanged(sender, e); //need to put this unfinished code in the page of PAYMENT //get a redirect to the page of PAYMENT //put in the basket the prescription items and wait for premition to check out //there is no PAYMENT WEBSITE in this PROJECT //or just do a POP UP that says the prescription has been used and the deatails of the order //like in the APPOINTMENT PAGE for the USER //delete the prescription from database } if (e.CommandName == "ShowMedicinePrice") { int rowNumber = Convert.ToInt32(e.CommandArgument); int medId = Convert.ToInt32(ShowPrescriptionGrid.Rows[rowNumber].Cells[3].Text); string medName = ShowPrescriptionGrid.Rows[rowNumber].Cells[4].Text; Pharmcy.PharmcyWS webser = new Pharmcy.PharmcyWS(); int medPrice = webser.GetMedicinePrice(medId); Response.Write("<script>alert('מחיר חבילת " + medName + " הוא " + medPrice + " שקלים')</script>"); } }
protected void SortPrescription_SelectedIndexChanged(object sender, EventArgs e) { //init the visible of the gridview and the close button ShowPrescriptionGrid.Visible = false; ClosePrescription.Visible = false; int x = SortPrescription.SelectedIndex; DataSet ds; PrescriptioService ps = new PrescriptioService(); User u = (User)Session["user"]; string whereClout = " where PrescriptionUserId='" + u.CUserId + "'"; //write every thing is 1 query //in the query put the PrescriptionId in cell 0 because this cell is visiable in the gridview if (x == 1) { whereClout += " ORDER BY PrescriptionDate"; //use query that sort by PrescriptionDate, show all the data } else if (x == 2) { whereClout += " ORDER BY PrescriptionDoctorId"; //use query that sort by PrescriptionDoctorId, show all the data } ds = ps.SortPrescription(whereClout); //DataSet temp = webser.GetCatagoryName() //check if ds is empty //if he is empty send popup that there is no prescription //else, shoe the date in the grid view if (ds.Tables[0].Rows.Count != 0) { ClosePrescription.Visible = true; ShowPrescriptionGrid.Visible = true; ShowPrescriptionGrid.DataSource = ds; ShowPrescriptionGrid.DataBind(); } else { Response.Write("<script>alert('לא נמצאו מרשמים')</script>"); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { User u = (User)Session["user"]; HelloLabel.Text = u.CUserName; PrescriptioService ps = new PrescriptioService(); string whereClout = " where PrescriptionUserId='" + u.CUserId + "'"; DataSet ds = ps.SortPrescription(whereClout); if (ds.Tables[0].Rows.Count != 0) { ClosePrescription.Visible = true; ShowPrescriptionGrid.Visible = true; ShowPrescriptionGrid.DataSource = ds; ShowPrescriptionGrid.DataBind(); } else { Response.Write("<script>alert('לא נמצאו מרשמים')</script>"); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Manager m = (Manager)Session["manager"]; HelloLabel.Text = m.CManagerName; string whereclout = " where DoctorId=PrescriptionDoctorId and UserId=PrescriptionUserId"; PrescriptioService ps = new PrescriptioService(); DataSet ds = ps.SortPrescriptionManager(whereclout); ShowPrescription.Visible = false; if (ds.Tables[0].Rows.Count != 0) { ClosePrescription.Visible = true; ShowPrescription.Visible = true; ShowPrescription.DataSource = ds; ShowPrescription.DataBind(); } else { Response.Write("<script>alert('לא נמצאו מרשמים')</script>"); } } }
protected void CheckoutButton_Click(object sender, EventArgs e) { User temp = (User)Session["user"]; if (temp == null) { Response.Write("<script>alert('על מנת לרכוש מוצרים עליך להיות לקוח רשום')</script>"); Response.Write("<script>window.open('http://localhost:49675/GuestHome.aspx');</script>"); return; } ShoppingBag sb = (ShoppingBag)Session["myShoppingBag"]; if (sb == null || sb.isEmpty()) { Response.Write("<script>alert('הסל ריק')</script>"); return; } //delete all the prescription from database presList = (List <DataSet>)Session["presList"]; int presId; PrescriptioService ps = new PrescriptioService(); if (presList != null) { foreach (DataSet d in presList) { presId = Convert.ToInt32(d.Tables[0].Rows[0]["PrescriptionId"].ToString()); ps.DeletePrescription(presId); } } //update all the medicine stock according to the current count Pharmcy.PharmcyWS webser = new Pharmcy.PharmcyWS(); int totalPrice = sb.GetTotalPrice(); List <MedicineInBag> medList = sb.GetProducts(); int countOfMedicine = 0, size = sb.getSize(), index = 0; //create medicineInBag variables string[] id = new string[size], name = new string[size], pn = new string[size], cn = new string[size]; int[] price = new int[size], s = new int[size], pro = new int[size], cat = new int[size], count = new int[size]; bool[] p = new bool[size]; foreach (MedicineInBag m in medList) { id[index] = m.CMedicineId; name[index] = m.CMedicineName; pn[index] = m.CMedicineInBagProducerName; cn[index] = m.CMedicineInBagCatagoryName; price[index] = m.CMedicinePrice; s[index] = m.CMedicineStock; pro[index] = m.CMedicineProducer; cat[index] = m.CMedicineCatagory; p[index] = m.CMedicineNeedPrescription; count[index] = m.CMedicineInBagMedicineCount; index++; ///////////////////////////////////////////////////////////////////////// /* * int currentStock = webser.GetMedicineStock(Convert.ToInt32(m.CMedicineId)); * countOfMedicine = currentStock - m.CMedicineInBagMedicineCount; * webser.UpdateMedCount(countOfMedicine,Convert.ToInt32(m.CMedicineId)); */ ////////////////////////////////////////////////////////////////////////// } //inseat to data base User u = (User)Session["user"]; /* * * /////////// * os.InsertOrder(o); * //////////////// * ///*/ //////////////////////////////////////////////////////////////////////////// webser.InseartOrder(id, name, price, p, s, pro, cat, pn, cn, count, u.CUserId); //////////////////////////////////////////////////////////////////////////// //init the shopping bag and the prescription list presList = new List <DataSet>(); Session["presList"] = new List <DataSet>(); sb = new ShoppingBag(); Session["myShoppingBag"] = new ShoppingBag(); Response.Write("<script>alert('ההזמנה בוצעה בהצלחה, עלות ההזמנה היא: " + totalPrice + " שקלים')</script>"); SortButton_Click(sender, e); }
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; } }