private void SelectShowList(object sender, EventArgs e) { int Id; try { Id = int.Parse(ListShow.SelectedItems[0].SubItems[1].Text); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); if (e is EventArgsForMedicine) { Id = ((EventArgsForMedicine)e).Id; } else { return; } } Medicine medicine1 = new Medicine(); medicine1 = MedicineHelper.GetMedicineWithId(Id); try { ImageShow.Image = ChangeBitmapHelper.ChangeBitMap(ImageShow, medicine1.Image_Medicine); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); ImageShow.Image = null; } LabelNgaySanXuat.Text = "Ngày Sản Xuất:" + medicine1.Min_Date_Of_Manufacture.Value.ToShortDateString() + " - " + medicine1.Max_Date_Of_Manufacture.Value.ToShortDateString(); LabelDongGoi.Text = "Đóng gói:" + medicine1.Packing; LabelSoLuongTrongMoiGoi.Text = "Số Lượng trong mỗi gói:" + medicine1.Unit; LabelGiaThanh.Text = "Giá Thành:" + ExtensionHelper.ChangeToCurrency(medicine1.Cost.ToString()); LabelMaDangKi.Text = "Mã Đăng Kí:" + medicine1.Registration_Number; LabelXuatXu.Text = "Xuất Xứ:" + medicine1.Source; labelGiaNhap.Text = "Giá Nhập:Từ " + ExtensionHelper.ChangeToCurrency(medicine1.Min_Import_Cost.ToString()) + " tới" + ExtensionHelper.ChangeToCurrency(medicine1.Max_Import_Cost.ToString()); }
private void button1_Click(object sender, EventArgs e) { int Id; try { Id = int.Parse(ListShow.SelectedItems[0].SubItems[1].Text); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); if (e is EventArgsForMedicine) { Id = ((EventArgsForMedicine)e).Id; } else { MessageBox.Show("Chọn thuốc để nhập !"); return; } } Medicine medicine1 = new Medicine(); medicine1 = MedicineHelper.GetMedicineWithId(Id); try { DateTime dateTime = new DateTime(int.Parse(TextBoxNamSanXuat.Text), int.Parse(TextBoxThangSanXuat.Text), int.Parse(TextBoxNgaySanXuat.Text)); medicine1.Date_Of_Manufacture = dateTime; if (medicine1.Date_Of_Manufacture >= DateTime.Now) { throw new Exception(); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); MessageBox.Show("Lỗi Nhập Vào Ngày Sản Xuất !"); return; } try { DateTime dateTime1; DateTime dateTime; DateTime dateTime2; int NgaySuDung = 0; int ThangSuDung = 0; int NamSuDung = 0; try { NgaySuDung = int.Parse(TextBoxNgaySuDung.Text); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } try { ThangSuDung = int.Parse(TextBoxThangSuDung.Text); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } try { NamSuDung = int.Parse(TextBoxNamSuDung.Text); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } if (NgaySuDung == 0 && ThangSuDung == 0 && NamSuDung == 0) { throw new Exception("Lỗi Nhập Vào Hạn Sử Dụng !"); } if (medicine1.Date_Of_Manufacture != null) { dateTime2 = new DateTime(medicine1.Date_Of_Manufacture.Value.Year, medicine1.Date_Of_Manufacture.Value.Month, medicine1.Date_Of_Manufacture.Value.Day); dateTime1 = new DateTime(dateTime2.AddYears(NamSuDung).Year, dateTime2.AddMonths(ThangSuDung).Month, dateTime2.AddDays(NgaySuDung).Day); medicine1.Expiry_Date = dateTime1; } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } try { int amount = int.Parse(textBoxSoLuong.Text); medicine1.Remain_Amount = amount; } catch (Exception ex) { MessageBox.Show("Lỗi Nhập Vào Số Lượng !"); return; } medicine1.ID_Category = new List <int?>(); medicine1.ID_Manufacturer = new List <int?>(); try { int idManufacturer = (int)(ComboBoxCongty.SelectedItem as ComboBoxItem).Value; if (!medicine1.ID_Manufacturer.Contains(idManufacturer)) { medicine1.ID_Manufacturer.Add(idManufacturer); } } catch (Exception ex) { MessageBox.Show("Hãy Chọn Công Ty Sản Xuất"); return; Debug.WriteLine(ex.ToString()); } try { decimal Cost = decimal.Parse(textBoxTienNhap.Text); medicine1.Cost = Cost; } catch { MessageBox.Show("Nhập vào số tiền mỗi đơn vị thuốc"); return; } //try //{ // int idCategory = (ComboBoxChonLoai.SelectedItem as ComboBoxItem).Value; // if (!medicine1.ID_Category.Contains(idCategory)) // medicine1.ID_Category.Add(idCategory); //} //catch (Exception ex) //{ // Debug.WriteLine(ex.ToString()); //} listToAdd.Add(new Tuple <Medicine, int>(medicine1, iteratorAdd)); ListViewItem listViewItem = new ListViewItem(new string[] { i.ToString(), medicine1.ID_Medicine.ToString(), medicine1.Name_Medicine, medicine1.Remain_Amount.ToString(), medicine1.Expiry_Date.Value.ToShortDateString(), ExtensionHelper.ChangeToCurrency((medicine1.Cost.Value * medicine1.Remain_Amount.Value).ToString()), iteratorAdd.ToString() }); ListNhapHang.Items.Add(listViewItem); iteratorAdd++; i++; decimal Total = 0; foreach (ListViewItem row in ListNhapHang.Items) { Total += decimal.Parse(ExtensionHelper.ChangeToNormalDecimal(row.SubItems[5].Text)); } labelTongTien.Text = ExtensionHelper.ChangeToCurrency(Total.ToString()) + " VND"; }