コード例 #1
0
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;

            context.Dispose();
            userIdentity.Dispose();
            this.Close();
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //try
            //{
            PharmacyDbContext db = new PharmacyDbContext();

            foreach (ListViewItem item in lvMedicine.Items)
            {
                Medicine medicine = new Medicine();

                medicine.Name        = item.SubItems[2].Text;
                medicine.Id          = UniqueNumber.GenerateUniqueNumber();
                medicine.CreatedBy   = currentUser;
                medicine.CreatedDate = DateTime.Now;
                medicine.GroupId     = GroupFactory.GetGroupId(item.SubItems[3].Text, currentUser);
                medicine.CompanyId   = CompanyFactory.GetCompanyId(item.SubItems[4].Text, currentUser);
                db.Medicine.Add(medicine);
            }
            db.SaveChanges();
            db.Dispose();
            MessageBox.Show(@"Save successful!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            lvMedicine.Items.Clear();
            //}
            //catch (Exception exception)
            //{
            //    MessageBox.Show("Saving Error:" + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
        }
コード例 #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string expenseType = txtExpenseType.Text;

            if (expenseType == "")
            {
                MessageBox.Show("Expense can't be empty!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            PharmacyDbContext db           = new PharmacyDbContext();
            ExpenseType       expenseTypes = new ExpenseType()
            {
                CreatedBy   = currentUser,
                CreatedDate = DateTime.Now,
                Id          = Guid.NewGuid().ToString(),
                Type        = expenseType
            };

            db.ExpenseType.Add(expenseTypes);
            db.SaveChanges();
            db.Dispose();
            MessageBox.Show("Save successful!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);

            txtExpenseType.Text = "";
        }
コード例 #4
0
        private void btnTodayDue_Click(object sender, EventArgs e)
        {
            DateTime          today = DateTime.Today;
            PharmacyDbContext db    = new PharmacyDbContext();
            int rowNo = 1;
            var data  = db.Voucher
                        .ToList()
                        .Where(d => d.CreatedDate.Date == today.Date && d.CustomerId != null)
                        .GroupBy(o => o.CustomerId)
                        .Select(x => new
            {
                SL           = rowNo++,
                CustomerId   = x.Key,
                CustomerName = x.Select(a => a.Customer.Name).FirstOrDefault(),
                Mobile       = x.Select(a => a.Customer.Mobile).FirstOrDefault(),
                Due          = x.Where(c => c.GLCode == GLCode.AccountReceivable).Sum(a => a.Dr - a.Cr) < 0 ? 0 : x.Where(c => c.GLCode == GLCode.AccountReceivable).Sum(a => a.Dr - a.Cr),
                Paid         = x.Where(c => c.GLCode == GLCode.Cash).Sum(a => a.Dr),
                TotalSale    = x.Where(c => c.GLCode == GLCode.SaleMedicine).Sum(a => a.Cr),
                Date         = x.Select(a => a.CreatedDate).FirstOrDefault().ToString("d")
            }).ToList();

            db.Dispose();
            dgvDue.Columns.Clear();
            dgvDue.DataSource = data;

            lblDueTotal.Text  = data.Sum(x => x.Due).ToString();    // db.Voucher.Where(a => a.GLCode == GLCode.AccountReceivable && a.CustomerId != null).ToList().Sum(x => x.Dr-x.Cr).ToString();
            lblPaidTotal.Text = data.Sum(x => x.Paid).ToString();   //db.Voucher.Where(a=>a.GLCode == GLCode.Cash && a.CustomerId != null).ToList().Sum(x => x.Dr).ToString();
            lblTotal.Text     = data.Sum(x => x.TotalSale).ToString();

            AddButton();

            MakeFullWidthScreen();
        }
コード例 #5
0
        private string GetGroup(string id)
        {
            PharmacyDbContext db   = new PharmacyDbContext();
            string            name = db.Groups.Where(g => g.Id == id).Select(s => s.Name).FirstOrDefault();

            db.Dispose();
            return(name);
        }
コード例 #6
0
        private string GetMedicineName(string id)
        {
            PharmacyDbContext db   = new PharmacyDbContext();
            string            name = db.Medicine.Where(s => s.Id == id).Select(a => a.Name).FirstOrDefault();

            db.Dispose();
            return(name);
        }
コード例 #7
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
コード例 #8
0
        private void btnPay_Click(object sender, EventArgs e)
        {
            PharmacyDbContext db = new PharmacyDbContext();

            SaveInvoice(db);
            db.SaveChanges();
            db.Dispose();
            MessageBox.Show("Save successful", "Paid!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }
コード例 #9
0
        private void SetLabelValue()
        {
            PharmacyDbContext db = new PharmacyDbContext();

            lblMedicine.Text = db.Medicine.Count().ToString();
            lblGroup.Text    = db.Groups.Count().ToString();
            lblcompany.Text  = db.Company.Count().ToString();
            db.Dispose();
        }
コード例 #10
0
        public SaveMedicine(string currentUser)
        {
            this.currentUser = currentUser;
            InitializeComponent();
            PharmacyDbContext db = new PharmacyDbContext();

            GetAutocompleteForCompany(db);
            GetAutocompleteForGroup(db);
            db.Dispose();
        }
コード例 #11
0
        public Salemedicine(string user)
        {
            currentUser = user;
            InitializeComponent();
            PharmacyDbContext db = new PharmacyDbContext();

            GetAutocompleteForMedicine(db);
            GetAutocompleteForCustomer(db);
            db.Dispose();
        }
コード例 #12
0
        private decimal GetPurchaseMedicine(string medicineId)
        {
            PharmacyDbContext db = new PharmacyDbContext();
            var count            = db.PurchaseSub.Where(m => m.MedicinId == medicineId)
                                   .ToList()
                                   .Sum(x => x.Quantity);

            db.Dispose();
            return(count);
        }
コード例 #13
0
        public void TearDown()
        {
            dbContext.InvoiceContents.RemoveRange(dbContext.InvoiceContents);
            dbContext.Invoices.RemoveRange(dbContext.Invoices);
            dbContext.Users.RemoveRange(dbContext.Users);
            dbContext.Medications.RemoveRange(dbContext.Medications);
            dbContext.SaveChanges();

            dbContext.Dispose();
        }
コード例 #14
0
        private void UpdateUnitPrice(string medicineName, string rate, DateTime exDate)
        {
            PharmacyDbContext db       = new PharmacyDbContext();
            decimal           price    = Convert.ToDecimal(rate);
            Medicine          medicine = db.Medicine.FirstOrDefault(x => x.Name == medicineName);

            medicine.UnitPrice   = price;
            medicine.ExpiredDate = exDate;
            db.SaveChanges();
            db.Dispose();
        }
コード例 #15
0
        private void btnSubmit_click(object sender, EventArgs e)
        {
            PharmacyDbContext db = new PharmacyDbContext();

            SaveInvoice(db);
            db.SaveChanges();
            db.Dispose();
            MessageBox.Show("Save successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

            ClearFields();
        }
コード例 #16
0
        private void btnSubmit_click(object sender, EventArgs e)
        {
            PharmacyDbContext db = new PharmacyDbContext();

            SaveInvoice(db);
            db.SaveChanges();
            db.Dispose();
            MessageBox.Show("Save successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            btnPrint.Enabled = true;
            txtNote.Text     = "";
            lvExpense.Items.Clear();
        }
コード例 #17
0
        public PurchaseMedicine(string user)
        {
            currentUser = user;
            InitializeComponent();
            PharmacyDbContext db = new PharmacyDbContext();

            GetAutocompleteForMedicine(db);
            GetAutocompleteForSupplier(db);
            GetAutocompleteForCompany(db);
            GetAutocompleteForGroup(db);
            db.Dispose();
        }
コード例 #18
0
        private bool IsMedicineExest(string medicine)
        {
            bool isExit           = false;
            PharmacyDbContext db  = new PharmacyDbContext();
            Medicine          med = db.Medicine.ToList().FirstOrDefault(x => x.Name == medicine);

            if (med != null)
            {
                isExit = true;
            }
            db.Dispose();
            return(isExit);
        }
コード例 #19
0
        private void btnSubmit_click(object sender, EventArgs e)
        {
            PharmacyDbContext db = new PharmacyDbContext();

            SaveInvoice(db);
            db.SaveChanges();
            db.Dispose();
            MessageBox.Show("Save successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);


            lvPurchaseMedicine.Items.Clear();
            txtDiscount.Text = "";
            txtDue.Text      = "";
            txtPaid.Text     = "";
            txtNote.Text     = "";
        }
コード例 #20
0
 private void frmNewUser_Load(object sender, EventArgs e)
 {
     lstRoles = context.Roles.Select(r => r.Name)?.ToList();
     if (lstRoles != null)
     {
         cmbRole.Properties.Items.AddRange(lstRoles);
         cmbRole.Text = lstRoles[0];
     }
     else
     {
         XtraMessageBox.Show("There are no role in database", "Error");
         context.Dispose();
         userIdentity.Dispose();
         this.Close();
     }
 }
コード例 #21
0
        public saveExpense(string user)
        {
            currentUser = user;
            InitializeComponent();
            PharmacyDbContext  db    = new PharmacyDbContext();
            List <ExpenseType> types = db.ExpenseType.ToList();
            ExpenseType        first = new ExpenseType
            {
                Id   = "0",
                Type = "-- select one --"
            };

            types.Insert(0, first);
            cbExpenseType.DataSource    = types;
            cbExpenseType.DisplayMember = "Type"; // types.Select(o => o.Type).ToString();
            cbExpenseType.ValueMember   = "Id";   // types.Select(o => o.Id).ToString();
            db.Dispose();
        }
コード例 #22
0
        private void DateRangeExpense()
        {
            DateTime            sdate = Convert.ToDateTime(dtpStartDate.Text);
            DateTime            edate = Convert.ToDateTime(dtpEndDate.Text);
            List <PurchaseList> list  = new List <PurchaseList>();
            PharmacyDbContext   db    = new PharmacyDbContext();
            int rowNo = 1;
            var data  = db.PurchaseSub
                        .Where(a => a.CreatedDate >= sdate && a.CreatedDate <= edate)
                        .ToList()
                        .Select(x => new
            {
                SL = rowNo++,
                x.MedicinId,
                x.Quantity,
                x.UnitPrice,
                x.Total,
                Date = x.CreatedDate.ToString("d")
            }).ToList();

            foreach (var item in data)
            {
                PurchaseList l = new PurchaseList
                {
                    SL           = item.SL.ToString(),
                    MedicineName = GetMedicineName(item.MedicinId),
                    Quantity     = item.Quantity,
                    UnitPrice    = item.UnitPrice,
                    Total        = item.Total,
                    Date         = item.Date
                };
                list.Add(l);
            }

            lblDueTotal.Text = db.PurchaseSub
                               .ToList()
                               .Where(a => a.CreatedDate >= sdate && a.CreatedDate <= edate)
                               .Sum(x => x.Total).ToString(); // db.Voucher.Where(a => a.GLCode == GLCode.AccountReceivable && a.CustomerId != null).ToList().Sum(x => x.Dr-x.Cr).ToString();
            // db.Voucher.Where(a => a.GLCode == GLCode.SaleMedicine && a.CustomerId != null).ToList().Sum(x => x.Cr).ToString();
            db.Dispose();
            dgvExpense.Columns.Clear();
            dgvExpense.DataSource = list;
            MakeFullWidthScreen();
        }
コード例 #23
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            // Dispose of managed resources here.
            if (disposing)
            {
                if (_disposeContext)
                {
                    context?.Dispose();
                }
            }

            // Dispose of any unmanaged resources not wrapped in safe handles.

            _disposed = true;
        }
コード例 #24
0
        private IEnumerable <Store> MedicineStore()
        {
            PharmacyDbContext db = new PharmacyDbContext();
            var data             = db.Medicine
                                   .OrderByDescending(o => o.ExpiredDate)
                                   .Include(s => s.Groups)
                                   .Include(i => i.Company)
                                   .ToList()
                                   .GroupBy(g => g.Id)
                                   .Select(s => new
            {
                Id           = s.Key,
                MedicineName = s.Select(a => a.Name).FirstOrDefault(),
                Type         = s.Select(a => a.MedicineType).FirstOrDefault(),
                ExpiredDate  = s.Select(a => a.ExpiredDate).FirstOrDefault(),
                Group        = s.Select(a => a.GroupId).FirstOrDefault(),
                Company      = s.Select(a => a.Company.Name).FirstOrDefault(),
                Purchased    = s.Sum(a => a.PurchaseSub.Sum(x => x.Quantity)),
                Sale         = s.Sum(a => a.SaleSub.Sum(x => x.Quantity)),
                Balance      = s.Sum(a => a.PurchaseSub.Sum(x => x.Quantity)) - s.Sum(a => a.SaleSub.Sum(x => x.Quantity))
            })
                                   .ToList();
            List <Store> storages = new List <Store>();

            foreach (var item in data)
            {
                Store store = new Store();
                store.Id          = item.Id;
                store.Name        = item.MedicineName;
                store.Company     = item.Company;
                store.ExpiredDate = item.ExpiredDate;
                store.GroupName   = GetGroup(item.Group);
                store.Purchased   = GetPurchaseMedicine(item.Id);
                store.Sold        = GetSaleMedicine(item.Id);
                store.Balance     = store.Purchased - store.Sold;
                storages.Add(store);
            }
            db.Dispose();
            return(storages);
        }
コード例 #25
0
        private void FixedDateExpense()
        {
            DateTime          date = Convert.ToDateTime(dtpStartDate.Text);
            PharmacyDbContext db   = new PharmacyDbContext();
            int rowNo = 1;
            var data  = db.ExpenseMain
                        .ToList()
                        .Where(d => d.CreatedDate.Date == date.Date)
                        .Select(x => new
            {
                SL     = rowNo++,
                Id     = x.Id,
                Amount = x.TotalAmount,
                Date   = x.CreatedDate
            }).ToList();

            db.Dispose();
            dgvExpense.Columns.Clear();
            dgvExpense.DataSource = data;
            AddButton();
            MakeFullWidthScreen();
        }
コード例 #26
0
        private void ShowData()
        {
            PharmacyDbContext db = new PharmacyDbContext();
            int rowNo            = 1;
            var data             = db.ExpenseMain
                                   .ToList()
                                   .Select(x => new
            {
                SL     = rowNo++,
                Id     = x.Id,
                Amount = x.TotalAmount,
                Date   = x.CreatedDate
            }).ToList();

            lblDueTotal.Text = data.Sum(x => x.Amount).ToString();     // db.Voucher.Where(a => a.GLCode == GLCode.AccountReceivable && a.CustomerId != null).ToList().Sum(x => x.Dr-x.Cr).ToString();
            // db.Voucher.Where(a => a.GLCode == GLCode.SaleMedicine && a.CustomerId != null).ToList().Sum(x => x.Cr).ToString();
            db.Dispose();
            dgvExpense.Columns.Clear();
            dgvExpense.DataSource = data;
            AddButton();
            MakeFullWidthScreen();
        }
コード例 #27
0
        private void ShowData()
        {
            PharmacyDbContext db = new PharmacyDbContext();
            int rowNo            = 1;
            var data             = db.PurchaseSub
                                   .ToList()
                                   .Select(x => new
            {
                SL = rowNo++,
                x.Id,
                x.MedicinId,
                x.Quantity,
                x.UnitPrice,
                x.Total,
                Date = x.CreatedDate.ToString("d")
            }).ToList();

            List <PurchaseList> list = data.Select(item => new PurchaseList
            {
                SL           = item.SL.ToString(),
                Id           = item.Id,
                MedicineName = GetMedicineName(item.MedicinId),
                Quantity     = item.Quantity,
                UnitPrice    = item.UnitPrice,
                Total        = item.Total,
                Date         = item.Date
            }).ToList();

            lblDueTotal.Text = db.PurchaseSub.Sum(x => x.Total).ToString(CultureInfo.CurrentCulture);     // db.Voucher.Where(a => a.GLCode == GLCode.AccountReceivable && a.CustomerId != null).ToList().Sum(x => x.Dr-x.Cr).ToString();
            // db.Voucher.Where(a => a.GLCode == GLCode.SaleMedicine && a.CustomerId != null).ToList().Sum(x => x.Cr).ToString();
            db.Dispose();
            dgvExpense.Columns.Clear();
            dgvExpense.DataSource         = list;
            dgvExpense.Columns[1].Visible = false;
            MakeFullWidthScreen();
            AddButton();
        }