private void button1_Click(object sender, EventArgs e) { string Login = textUsername.Text.Trim(); string Pass = txtPassword.Text.Trim(); if (Login != "admin" || Pass != "123") { MessageBox.Show("Please enter correct username or pass", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Aptek ZeferanAptek = new Aptek("Zeferan"); Medicine medicine = new Medicine(this, ZeferanAptek); medicine.Show(); medicine.dataGridView1.DataSource = ZeferanAptek.GetDerman(); medicine.comboBox1.DataSource = ZeferanAptek.GetDerman(); this.Hide(); }
private void btnCreate_Click(object sender, EventArgs e) { string medicine = txtMedicine.Text; string price = txtPrice.Text; string TypeMedicine = txtTypeMedicine.Text; if (medicine == "" || price == "" || TypeMedicine == "") { MessageBox.Show("Xanani doldurun", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Medicine medicine1 = new Medicine { Name = medicine, Price = price, Typemedicine = TypeMedicine }; _pharmacy.AddMedicine(medicine1); dgvList.DataSource = _pharmacy.GetMedicines(); dgvList.DataSource = null; dgvList.DataSource = _pharmacy.GetMedicines(); txtMedicine.Text = null; txtTypeMedicine.Text = null; }
public static void DeleteMedicine() { try { int id = Ask.ForMedicineId("Podaj ID leku: "); using (var medicine = new Medicine()) { medicine.Reload(id); if (medicine.OrderExistsForMedicine()) { ConsoleEx.WriteLine(ConsoleColor.Red, "Lek nie może zostać usunięty ponieważ istnieją dla niego zamówienia. "); } else { var medicineToDelete = new List <Medicine>() { medicine }; DisplayMedicineList(medicineToDelete); Console.WriteLine(); if (Ask.ForBool("Czy na pewno chcesz usunąć lek: t/n ")) { medicine.Remove(); ConsoleEx.WriteLine(Console.ForegroundColor, "Lek został usunięty. "); Console.WriteLine(); } } } } catch (Exception e) { ConsoleEx.WriteLine(ConsoleColor.Red, "Wystąpił błąd. ERROR: {0}", e.Message); } }
/// <summary> /// Menu for medicines /// </summary> public static void Choice() { ConsoleEx.WriteLine("Avaiable commands for Medicines:\n1. Show all (show)\n2. Add medicine (add)\n3. Edit medicine (edit)\n4. Remove medicine (rem)\n5. Go to previous menu (exit)", ConsoleColor.Yellow); Medicine med = new Medicine(); string choice = Console.ReadLine(); if (choice == "1" || choice.ToLower() == "show") { Console.Clear(); med.ShowAll(); } else if (choice == "2" || choice.ToLower() == "add") { Console.Clear(); med.Save(); } else if (choice == "3" || choice == "edit") { Console.Clear(); Console.Write("Write Medicine's ID to "); ConsoleEx.Write("Edit: ", ConsoleColor.Cyan); int id = Int32.Parse(Console.ReadLine()); med.Reload(id); } else if (choice == "4" || choice.ToLower() == "remove") { Console.Clear(); Console.Write("Write Medicine's ID to "); ConsoleEx.Write("Remove: ", ConsoleColor.Red); int id = Int32.Parse(Console.ReadLine()); med.Remove(id); } else if (choice == "5" || choice.ToLower() == "exit") { Console.Clear(); return; } }
public static int ForMedicineId(string message) { bool exists; int id; int count = 0; do { id = ForInt(message); exists = Medicine.CheckIfExists(id); if (exists) { //break; return(id); } ConsoleEx.Write(ConsoleColor.Red, "Lek o podanym ID nie istnieje\n"); count++; if (count >= 2) { if (Ask.ForBool("Wyświetlić wszystkie leki: t/n ")) { Console.WriteLine(); ProgramLogic.DisplayMedicineList(Medicine.LoadAll()); Console.WriteLine(); } count = 0; } } while (!exists); return(id); }
private static void AddCMD(string commandType, string[] commandValues, Prescription lastPrescription, Medicine lastMedicine) { if (commandType == "AddMedicine") { if (commandValues.Length == 6) { //[int id],[string name],[string manufacturer],[decimal price],[int amount],[bool withPrescription] int id = Convert.ToInt32(commandValues[0]); string name = Convert.ToString(commandValues[1]); string manufacturer = Convert.ToString(commandValues[2]); decimal price = Convert.ToDecimal(commandValues[3]); int amount = Convert.ToInt32(commandValues[4]); bool withPrescription = Convert.ToBoolean(commandValues[5]); Medicine myMedicine = new Medicine(id, name, manufacturer, price, amount, withPrescription); myMedicine.Save(); Program.LastMedicine = myMedicine; } else { Console.WriteLine("Nieprawidlowa ilość, lub format atrybutów."); } } else if (commandType == "AddPrescription") { if (commandValues.Length == 4) { //[int id],[string customerName],[string pesel],[int prescriptionNumber] int id = Convert.ToInt32(commandValues[0]); string customerName = Convert.ToString(commandValues[1]); string pesel = Convert.ToString(commandValues[2]); int prescriptionNumber = Convert.ToInt32(commandValues[3]); Prescription myPrescription = new Prescription(id, customerName, pesel, prescriptionNumber); myPrescription.Save(); Program.LastPrescription = myPrescription; } else { Console.WriteLine("Nieprawidlowa ilość, lub format atrybutów."); } } else if (commandType == "AddOrder") { if (commandValues.Length == 5) { //[int id],[Prescription prescriptionObj],[Medicine medicineObj],[string date],[int amount] int id = Convert.ToInt32(commandValues[0]); int lastPresciptionNumber = Convert.ToInt32(commandValues[1]); int lastMedicineNumber = Convert.ToInt32(commandValues[2]); if (lastPresciptionNumber != 0) { Program.LastPrescription = new Prescription(lastPresciptionNumber); } if (lastMedicineNumber != 0) { Program.LastMedicine = new Medicine(lastMedicineNumber); } string date = Convert.ToString(commandValues[3]); int amount = Convert.ToInt32(commandValues[4]); if (LastPrescription != null && LastMedicine != null) { Order myOrder = new Order(id, LastPrescription, LastMedicine, date, amount); myOrder.Save(); Program.LastOrder = myOrder; } else { Console.WriteLine("Nie udało się utworzyć [Order]"); } } else { Console.WriteLine("Nieprawidlowa ilość, lub format atrybutów."); } } }
protected void Button2_Click(object sender, EventArgs e) { Medicine m = new Medicine(); m.deleteMed(DropDownList1.Text.ToString()); }
public void AddMedicine(Medicine m) { medicines.Add(m); }
static void Main(string[] args) { while (true) { ConsoleEx.WriteLine(Console.ForegroundColor, "I. Zarządzania listą leków: "); ConsoleEx.Write(Console.ForegroundColor, " 1. Dodanie leku - ".PadRight(40)); ConsoleEx.WriteLine(ConsoleColor.Green, "add"); ConsoleEx.Write(Console.ForegroundColor, " 2. Edycja leku - ".PadRight(40)); ConsoleEx.WriteLine(ConsoleColor.Green, "mod"); ConsoleEx.Write(Console.ForegroundColor, " 3. Usuwanie leku - ".PadRight(40)); ConsoleEx.WriteLine(ConsoleColor.Green, "del"); ConsoleEx.Write(Console.ForegroundColor, " 4. Wyświetlenie listy leków - ".PadRight(40)); ConsoleEx.WriteLine(ConsoleColor.Green, "show"); ConsoleEx.Write(Console.ForegroundColor, " 5. Wyszukiwanie leków - ".PadRight(40)); ConsoleEx.WriteLine(ConsoleColor.Green, "find"); ConsoleEx.WriteLine(Console.ForegroundColor, "II. Sprzedaż leków: "); ConsoleEx.Write(Console.ForegroundColor, " 1. Dodanie zamówienia - ".PadRight(40)); ConsoleEx.WriteLine(ConsoleColor.Green, "ord"); ConsoleEx.WriteLine(Console.ForegroundColor, "\nWyjście - exit "); Console.WriteLine(); string input = Ask.ForString("Wpisz polecenie: ").ToLower(); if (input == "exit") { break; } if (input == "add") { DisplayHeader(ConsoleColor.Green, "DODWANIE LEKU"); bool addNext; do { ProgramLogic.AddMedicine(); Console.WriteLine(); addNext = Ask.ForBool("Dodać kolejny lek t/n: "); Console.WriteLine(); } while (addNext); } if (input == "mod") { DisplayHeader(ConsoleColor.Green, "MODYFIKACJA LEKU"); bool modNext; do { ProgramLogic.ModifyMedicine(); Console.WriteLine(); modNext = Ask.ForBool("Czy zmieniany będzie kolejny lek t/n: "); Console.WriteLine(); } while (modNext); } if (input == "show") { DisplayHeader(ConsoleColor.Green, "LISTA WSZYSTKICH LEKÓW"); ProgramLogic.DisplayMedicineList(Medicine.LoadAll()); Console.WriteLine(); } if (input == "del") { DisplayHeader(ConsoleColor.Green, "USUWANIE LEKU"); bool delNext; do { ProgramLogic.DeleteMedicine(); Console.WriteLine(); delNext = Ask.ForBool("Czy usuwany będzie kolejny lek t/n: "); Console.WriteLine(); } while (delNext); } if (input == "ord") { DisplayHeader(ConsoleColor.Green, "SKŁADANIE ZAMÓWIENIA"); bool ordNext; do { ProgramLogic.AddOrder(); Console.WriteLine(); ordNext = Ask.ForBool("Czy dodać kolejne zamówienie t/n: "); Console.WriteLine(); } while (ordNext); } if (input == "find") { DisplayHeader(ConsoleColor.Green, "WYSZUKIWANIE LEKU"); bool findNext; do { ProgramLogic.SearchForMedicine(); Console.WriteLine(); findNext = Ask.ForBool("Czy wyszukać kolejny lek t/n: "); Console.WriteLine(); } while (findNext); } } void DisplayHeader(ConsoleColor color, string header) { ConsoleEx.WriteLine(color, "".PadLeft(header.Length + 4, '-')); ConsoleEx.WriteLine(color, $"--{header}--"); ConsoleEx.WriteLine(color, "".PadLeft(header.Length + 4, '-')); } }
/// <summary> /// Save medicine to Database /// </summary> public override void Save() { do { try { Console.WriteLine("Medicine Name: "); string name = Console.ReadLine(); Console.WriteLine("Manufacturer: "); string manufacturer = Console.ReadLine(); Console.WriteLine("Price: "); decimal price = Decimal.Parse(Console.ReadLine()); Console.WriteLine("Amount: "); int amount = Int32.Parse(Console.ReadLine()); Console.WriteLine("With Prescription?(True/False):"); bool withPrescription = bool.Parse(Console.ReadLine()); Medicine med = new Medicine(name, manufacturer, price, amount, withPrescription); using (var connection = ActiveRecord.Open()) { var sqlCommand = new SqlCommand(); sqlCommand.Connection = connection; sqlCommand.CommandText = @"INSERT INTO Medicines (Name, Manufacturer, Price, Amount, WithPrescription) VALUES (@Name, @Manufacturer, @Price, @Amount, @WithPrescription);" ; var sqlNameParam = new SqlParameter { DbType = System.Data.DbType.AnsiString, Value = med.Name, ParameterName = "@Name" }; var sqlManufacturerParam = new SqlParameter { DbType = System.Data.DbType.AnsiString, Value = med.Manufacturer, ParameterName = "@Manufacturer" }; var sqlPriceParam = new SqlParameter { DbType = System.Data.DbType.Decimal, Value = med.Price, ParameterName = "@Price" }; var sqlAmountParam = new SqlParameter { DbType = System.Data.DbType.Int32, Value = med.Amount, ParameterName = "@Amount" }; var sqlWithPrescriptionParam = new SqlParameter { DbType = System.Data.DbType.Boolean, Value = med.WithPrescription, ParameterName = "@WithPrescription" }; sqlCommand.Parameters.Add(sqlNameParam); sqlCommand.Parameters.Add(sqlManufacturerParam); sqlCommand.Parameters.Add(sqlPriceParam); sqlCommand.Parameters.Add(sqlAmountParam); sqlCommand.Parameters.Add(sqlWithPrescriptionParam); sqlCommand.ExecuteNonQuery(); ConsoleEx.WriteLine("Successfully added", ConsoleColor.Green); Console.WriteLine("Do you want to add another? [yes/no]"); string ans = Console.ReadLine(); if (ans.ToLower() == "no") { break; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } while (true); }
private static void EditMed(int id) { try { Console.WriteLine("Medicine Name:"); string name = Console.ReadLine(); Console.WriteLine("Manufacturer:"); string manufacturer = Console.ReadLine(); Console.WriteLine("Price:"); decimal price = Decimal.Parse(Console.ReadLine()); Console.WriteLine("Amount:"); int amount = Int32.Parse(Console.ReadLine()); Console.WriteLine("With Prescription?(True/False):"); bool withPrescription = bool.Parse(Console.ReadLine()); var medicine = new Medicine(name, manufacturer, price, amount, withPrescription); using (SqlConnection connection = new SqlConnection(connectionString)) { var sqlCommand = new SqlCommand(); sqlCommand.Connection = connection; sqlCommand.CommandText = @"UPDATE Medicines SET Name = @Name, Manufacturer = @Manufacturer, Price = @Price, Amount = @Amount, WithPrescription = @WithPrescription WHERE ID = @id;" ; var sqlIdParam = new SqlParameter { DbType = System.Data.DbType.Int32, Value = id, ParameterName = "@id" }; var sqlNameParam = new SqlParameter { DbType = System.Data.DbType.AnsiString, Value = medicine.Name, ParameterName = "@Name" }; var sqlManufacturerParam = new SqlParameter { DbType = System.Data.DbType.AnsiString, Value = medicine.Manufacturer, ParameterName = "@Manufacturer" }; var sqlPriceParam = new SqlParameter { DbType = System.Data.DbType.Decimal, Value = medicine.Price, ParameterName = "@Price" }; var sqlAmountParam = new SqlParameter { DbType = System.Data.DbType.Int32, Value = medicine.Amount, ParameterName = "@Amount" }; var sqlWithPrescriptionParam = new SqlParameter { DbType = System.Data.DbType.Boolean, Value = medicine.WithPrescription, ParameterName = "@WithPrescription" }; sqlCommand.Parameters.Add(sqlIdParam); sqlCommand.Parameters.Add(sqlNameParam); sqlCommand.Parameters.Add(sqlManufacturerParam); sqlCommand.Parameters.Add(sqlPriceParam); sqlCommand.Parameters.Add(sqlAmountParam); sqlCommand.Parameters.Add(sqlWithPrescriptionParam); connection.Open(); sqlCommand.ExecuteNonQuery(); connection.Close(); } } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// Change medicine from Database /// </summary> /// <param name="id"> Medicine's id </param> public override void Reload(int id) { try { Console.WriteLine("Medicine Name: "); string name = Console.ReadLine(); Console.WriteLine("Manufacturer: "); string manufacturer = Console.ReadLine(); Console.WriteLine("Price: "); decimal price = Decimal.Parse(Console.ReadLine()); Console.WriteLine("Amount: "); int amount = Int32.Parse(Console.ReadLine()); Console.WriteLine("With Prescription?(True/False): "); bool withPrescription = bool.Parse(Console.ReadLine()); var med = new Medicine(name, manufacturer, price, amount, withPrescription); using (var connection = ActiveRecord.Open()) { var sqlCommand = new SqlCommand(); sqlCommand.Connection = connection; sqlCommand.CommandText = @"UPDATE Medicines SET Name = @Name, Manufacturer = @Manufacturer, Price = @Price, Amount = @Amount, WithPrescription = @WithPrescription WHERE MedicineID = @id;" ; var sqlIdParam = new SqlParameter { DbType = System.Data.DbType.Int32, Value = id, ParameterName = "@id" }; var sqlNameParam = new SqlParameter { DbType = System.Data.DbType.AnsiString, Value = med.Name, ParameterName = "@Name" }; var sqlManufacturerParam = new SqlParameter { DbType = System.Data.DbType.AnsiString, Value = med.Manufacturer, ParameterName = "@Manufacturer" }; var sqlPriceParam = new SqlParameter { DbType = System.Data.DbType.Decimal, Value = med.Price, ParameterName = "@Price" }; var sqlAmountParam = new SqlParameter { DbType = System.Data.DbType.Int32, Value = med.Amount, ParameterName = "@Amount" }; var sqlWithPrescriptionParam = new SqlParameter { DbType = System.Data.DbType.Boolean, Value = med.WithPrescription, ParameterName = "@WithPrescription" }; sqlCommand.Parameters.Add(sqlIdParam); sqlCommand.Parameters.Add(sqlNameParam); sqlCommand.Parameters.Add(sqlManufacturerParam); sqlCommand.Parameters.Add(sqlPriceParam); sqlCommand.Parameters.Add(sqlAmountParam); sqlCommand.Parameters.Add(sqlWithPrescriptionParam); sqlCommand.ExecuteNonQuery(); ConsoleEx.WriteLine("Successfully edited", ConsoleColor.Green); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
public static void AddOrder() { try { int id = Ask.ForMedicineId("Podaj ID leku do sprzedaży: "); DateTime saleDate = Ask.ForDate("Podaj datę sprzedaży bądź pozostaw puste aby uzupełnić bieżącą datą: ", true, DateTime.Now); decimal amount = Ask.ForDecimal("Podaj ilość sprzedawanych sztuk: "); using (var medicine = new Medicine()) { medicine.Reload(id); while (medicine.Amount < amount) { ConsoleEx.WriteLine(ConsoleColor.Red, "Wprowadzona ilość sztuk przekracza ilość w magazynie. "); if (Ask.ForBool($"Czy ustawić ilość na maksymalną dostepną ilość {medicine.Amount} t/n: ")) { amount = medicine.Amount; } else { amount = Ask.ForDecimal("Podaj nową ilość sprzedawanych sztuk: "); } } int? prescriptioId = null; Prescription prescription = null; if (medicine.WithPrescription) { string customerName = Ask.ForString("Podaj imię i nazwisko: "); string pesel = Ask.ForPesel("Podaje PESEL: "); string prescriptionNumber = Ask.ForString("Podaj numer recepty: "); prescription = new Prescription(customerName, pesel, prescriptionNumber); } if (Ask.ForBool($"Czy zapisać wprowadzone zamówienie t/n: ")) { medicine.Amount -= amount; medicine.Save(); if (medicine.WithPrescription && prescription != null) { using (prescription) { prescription.Save(); prescriptioId = prescription.ID; } } using (var order = new Order(prescriptioId, id, saleDate, amount)) { order.Save(); } } } } catch (Exception e) { ConsoleEx.WriteLine(ConsoleColor.Red, "Wystąpił błąd. ERROR: {0}", e.Message); } }
public static void SearchForMedicine() { //To do: //0. działa, ale do zmiany, //1. dodać zależność między typem a operatorem, //2. dodać dynamiczne generowanie poszczególnych list wyborów, //3. dodać mozliwość wyboru filtrowania po więcej niż jednym polu Console.WriteLine("Pola dostępne dla leków: "); Console.WriteLine(" 1. ID"); Console.WriteLine(" 2. Nazwa"); Console.WriteLine(" 3. Producent"); Console.WriteLine(" 4. Cena"); Console.WriteLine(" 5. Ilosc"); Console.WriteLine(" 6. Na receptę"); int fieldNum = Ask.ForIntListItem("Wybierz pole: ", 1, 6); Console.WriteLine(); Console.WriteLine("Operatory dostępne podczas wyszukiwania: "); Console.WriteLine(" 1. Równy"); Console.WriteLine(" 2. Różny"); Console.WriteLine(" 3. Zawiera"); Console.WriteLine(" 4. Zakres/Pomiędzy"); Console.WriteLine(" 5. Większy"); Console.WriteLine(" 6. Większy równy"); Console.WriteLine(" 7. Mniejszy"); Console.WriteLine(" 8. Mniejszy równy"); int conditionNum = Ask.ForIntListItem("Wybierz operator: ", 1, 8); string selectedField = ""; string selectedOperator = ""; object givenValue; object givenValue2; var sqlParam = new List <SqlParameter>(); switch (fieldNum) { default: selectedField = "ID"; if (conditionNum == 4) { givenValue = Ask.ForInt("Podaj wartość od: "); givenValue2 = Ask.ForInt("Podaj wartość do: "); sqlParam.Add(new SqlParameter() { ParameterName = "@" + selectedField.ToLower() + "To", Value = givenValue2 }); break; } givenValue = Ask.ForInt("Podaj wartość: "); break; case 2: selectedField = "Name"; if (conditionNum == 4) { givenValue = Ask.ForString("Podaj wartość od: "); givenValue2 = Ask.ForString("Podaj wartość do: "); sqlParam.Add(new SqlParameter() { ParameterName = "@" + selectedField.ToLower() + "To", Value = givenValue2 }); break; } givenValue = Ask.ForString("Podaj wartość: "); break; case 3: selectedField = "Manufacturer"; if (conditionNum == 4) { givenValue = Ask.ForString("Podaj wartość od: "); givenValue2 = Ask.ForString("Podaj wartość do: "); sqlParam.Add(new SqlParameter() { ParameterName = "@" + selectedField.ToLower() + "To", Value = givenValue2 }); break; } givenValue = Ask.ForString("Podaj wartość: "); break; case 4: selectedField = "Price"; if (conditionNum == 4) { givenValue = Ask.ForDecimal("Podaj wartość od: "); givenValue2 = Ask.ForDecimal("Podaj wartość do: "); sqlParam.Add(new SqlParameter() { ParameterName = "@" + selectedField.ToLower() + "To", Value = givenValue2 }); break; } givenValue = Ask.ForDecimal("Podaj wartość: "); break; case 5: selectedField = "Amount"; if (conditionNum == 4) { givenValue = Ask.ForString("Podaj wartość od: "); givenValue2 = Ask.ForString("Podaj wartość do: "); sqlParam.Add(new SqlParameter() { ParameterName = "@" + selectedField.ToLower() + "To", Value = givenValue2 }); break; } givenValue = Ask.ForString("Podaj wartość: "); break; case 6: selectedField = "WithPrescription"; if (conditionNum == 4) { givenValue = Ask.ForBool("Podaj wartość od: "); givenValue2 = Ask.ForBool("Podaj wartość do: "); sqlParam.Add(new SqlParameter() { ParameterName = "@" + selectedField.ToLower() + "To", Value = givenValue2 }); break; } givenValue = Ask.ForBool("Podaj wartość: "); break; } switch (conditionNum) { default: selectedOperator = " = #field#"; break; case 2: selectedOperator = " <> #field#"; break; case 3: selectedOperator = " like '%'+#field#+'%'"; break; case 4: selectedOperator = " between #field# and #field2#"; break; case 5: selectedOperator = " > #field#"; break; case 6: selectedOperator = " >= #field#"; break; case 7: selectedOperator = " < #field#"; break; case 8: selectedOperator = " <= #field#"; break; } sqlParam.Add(new SqlParameter() { ParameterName = "@" + selectedField.ToLower(), Value = givenValue }); string whereClausule = " where " + selectedField + selectedOperator.Replace("#field#", "@" + selectedField.ToLower()).Replace("#field2#", "@" + selectedField.ToLower() + "To"); DisplayMedicineList(Medicine.Search(whereClausule, sqlParam.ToArray())); }
private static void AddMed(Medicine medicine) { try { using (SqlConnection connection = new SqlConnection(connectionString)) { var sqlCommand = new SqlCommand(); sqlCommand.Connection = connection; sqlCommand.CommandText = @"INSERT INTO Medicines (Name, Manufacturer, Price, Amount, WithPrescription) VALUES (@Name, @Manufacturer, @Price, @Amount, @WithPrescription);" ; var sqlNameParam = new SqlParameter { DbType = System.Data.DbType.AnsiString, Value = medicine.Name, ParameterName = "@Name" }; var sqlManufacturerParam = new SqlParameter { DbType = System.Data.DbType.AnsiString, Value = medicine.Manufacturer, ParameterName = "@Manufacturer" }; var sqlPriceParam = new SqlParameter { DbType = System.Data.DbType.Decimal, Value = medicine.Price, ParameterName = "@Price" }; var sqlAmountParam = new SqlParameter { DbType = System.Data.DbType.Int32, Value = medicine.Amount, ParameterName = "@Amount" }; var sqlWithPrescriptionParam = new SqlParameter { DbType = System.Data.DbType.Boolean, Value = medicine.WithPrescription, ParameterName = "@WithPrescription" }; sqlCommand.Parameters.Add(sqlNameParam); sqlCommand.Parameters.Add(sqlManufacturerParam); sqlCommand.Parameters.Add(sqlPriceParam); sqlCommand.Parameters.Add(sqlAmountParam); sqlCommand.Parameters.Add(sqlWithPrescriptionParam); connection.Open(); sqlCommand.ExecuteNonQuery(); } } catch (Exception e) { Console.WriteLine(e.Message); } }
private static void RemoveCMD(string[] commandSplited) { if (commandSplited[1] == "Medicine") { Console.WriteLine("Wprowadz ID do usunięcia, lub wpisz Yes aby usnąć wczesniej wybrany."); string com = Console.ReadLine(); int val = Convert.ToInt32(com); if (com.Contains("Yes") && LastMedicine != null) { LastMedicine.Remove(); LastMedicine = null; } else if (val > 0) { LastMedicine = new Medicine(val); if (LastMedicine != null) { LastMedicine.Remove(); LastMedicine = null; } else { Console.WriteLine("Błąd."); } } else { Console.WriteLine("Niepoprawna komenda."); } } else if (commandSplited[1] == "Order") { Console.WriteLine("Wprowadz ID do usunięcia, lub wpisz Yes aby usnąć wczesniej wybrany."); string com = Console.ReadLine(); int val = Convert.ToInt32(com); if (com.Contains("Yes") && LastOrder != null) { LastOrder.Remove(); LastOrder = null; } else if (val > 0) { LastOrder = new Order(val); if (LastOrder != null) { LastOrder.Remove(); LastOrder = null; } else { Console.WriteLine("Błąd."); } } else { Console.WriteLine("Niepoprawna komenda."); } } else if (commandSplited[1] == "Prescription") { Console.WriteLine("Wprowadz ID do usunięcia, lub wpisz Yes aby usnąć wczesniej wybrany."); string com = Console.ReadLine(); int val = Convert.ToInt32(com); if (com.Contains("Yes") && LastPrescription != null) { LastPrescription.Remove(); LastPrescription = null; } else if (val > 0) { LastPrescription = new Prescription(val); if (LastPrescription != null) { LastPrescription.Remove(); LastPrescription = null; } else { Console.WriteLine("Błąd."); } } else { Console.WriteLine("Niepoprawna komenda."); } } else { Console.WriteLine("Niepoprawna komenda."); } }
public override void Reload() { if (ID == 0) { throw new Exception("Reload - ID nie moze być 0"); } Open(); SqlCommand cmd = new SqlCommand() { CommandText = "SELECT *" + "FROM [MyPharmacyDB].[dbo].[Orders]" + "WHERE [ID] = @id", CommandType = CommandType.Text, Connection = _connection, }; SqlParameter para1 = new SqlParameter() { ParameterName = "@id", Value = ID, DbType = DbType.Int32 }; cmd.Parameters.Add(para1); try { using (SqlDataReader sqlReader = cmd.ExecuteReader()) { if (sqlReader.HasRows) { while (sqlReader.Read()) { if (sqlReader.FieldCount == 5) { ID = Convert.ToInt32(sqlReader.GetValue(0)); _prescription = new Prescription(Convert.ToInt32(sqlReader.GetValue(1))); _medicine = new Medicine(Convert.ToInt32(sqlReader.GetValue(2))); _date = Convert.ToString(sqlReader.GetValue(3)); _amount = Convert.ToInt32(sqlReader.GetValue(4)); } else { OnFailAction?.Invoke("ZłyFieldCount."); } } } else { OnFailAction?.Invoke($"Klient o identyfikatorze {ID} nie istnieje."); throw new Exception("ID = 0, lub rekord nie istnieje."); } OnSuccesAction?.Invoke($"[Prescriptions] - Pomyślnie odświerzono rekord. ID = {ID}"); } } catch (Exception ex) { //Console.WriteLine(ex.Message, ex.StackTrace); OnFailAction?.Invoke($"{ex.Message}"); } finally { Close(); } }
protected void Button2_Click(object sender, EventArgs e) { Label1.Text = (0).ToString(); if (TextBox22.Text.ToString() != "") { if (TextBox3.Text.ToString() != "") { Medicine m = new Medicine(); m.findMedByBar(TextBox3.Text.ToString()); TextBox2.Text = m.Name.ToString(); Label1.Text = (float.Parse(Label1.Text) + m.Price * float.Parse(TextBox1.Text)).ToString(); } if (TextBox6.Text.ToString() != "") { Medicine m1 = new Medicine(); m1.findMedByBar(TextBox6.Text.ToString()); TextBox5.Text = m1.Name.ToString(); Label1.Text = (float.Parse(Label1.Text) + m1.Price * float.Parse(TextBox4.Text)).ToString(); } if (TextBox9.Text.ToString() != "") { Medicine m2 = new Medicine(); m2.findMedByBar(TextBox9.Text.ToString()); TextBox8.Text = m2.Name.ToString(); Label1.Text = (float.Parse(Label1.Text) + m2.Price * float.Parse(TextBox7.Text)).ToString(); } if (TextBox12.Text.ToString() != "") { Medicine m3 = new Medicine(); m3.findMedByBar(TextBox12.Text.ToString()); TextBox11.Text = m3.Name.ToString(); Label1.Text = (float.Parse(Label1.Text) + m3.Price * float.Parse(TextBox10.Text)).ToString(); } if (TextBox15.Text.ToString() != "") { Medicine m4 = new Medicine(); m4.findMedByBar(TextBox15.Text.ToString()); TextBox14.Text = m4.Name.ToString(); Label1.Text = (float.Parse(Label1.Text) + m4.Price * float.Parse(TextBox13.Text)).ToString(); } if (TextBox18.Text.ToString() != "") { Medicine m5 = new Medicine(); m5.findMedByBar(TextBox18.Text.ToString()); TextBox17.Text = m5.Name.ToString(); Label1.Text = (float.Parse(Label1.Text) + m5.Price * float.Parse(TextBox16.Text)).ToString(); } if (TextBox21.Text.ToString() != "") { Medicine m6 = new Medicine(); m6.findMedByBar(TextBox21.Text.ToString()); TextBox20.Text = m6.Name.ToString(); Label1.Text = (float.Parse(Label1.Text) + m6.Price * float.Parse(TextBox19.Text)).ToString(); } Button3.Visible = true; Order1 o = new Order1(TextBox22.Text.ToString(), Session["Id"].ToString()); o.addOrder(); } }
//method add medicines public void AddMedicine(Medicine med) { medicines.Add(med); }