Beispiel #1
0
        public string GetCustomerIdByName(string name, PharmacyDbContext db)
        {
            if (name == "")
            {
                name = "Unknown";
            }
            Customer customer = db.Customer.FirstOrDefault(i => i.Name == name);

            if (customer != null)
            {
                return(customer.Id);
            }
            else
            {
                customer = new Customer
                {
                    Id          = UniqueNumber.GenerateUniqueNumber(),
                    Name        = name,
                    Mobile      = txtPhone.Text,
                    CreatedBy   = currentUser,
                    CreatedDate = DateTime.Now
                };
                db.Customer.Add(customer);
                db.SaveChanges();
                return(customer.Id);
            }
        }
        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);
            //}
        }
Beispiel #3
0
        private void InsertObjectiveSub(ObjectiveSub sub)
        {
            var mainId =
                GetUnitOfWork()
                .ObjectiveMainRepository.Get()
                .Where(a => a.EmployeeId == CreatedBy && a.IsActive == true)
                .Select(s => s.Id)
                .FirstOrDefault();
            int weight = 0;

            if (mainId != Guid.Empty)
            {
                weight = GetUnitOfWork().ObjectiveSubRepository.Get().Where(a => a.ObjectiveMainId == mainId).Sum(s => s.Weight ?? 0) + sub.Weight ?? 0;
            }

            if (sub.Id != null)
            {
                if (weight - sub.Weight > 100)
                {
                    throw new Exception("Weight should not be greater then 100");
                }
                ObjectiveSub ob = GetUnitOfWork().ObjectiveSubRepository.Get().FirstOrDefault(a => a.Id == sub.Id);
                if (ob != null)
                {
                    ob.KPI         = sub.KPI;
                    ob.Note        = sub.Note;
                    ob.Target      = sub.Target;
                    ob.Weight      = sub.Weight;
                    ob.Title       = sub.Title;
                    ob.UpdatedBy   = CreatedBy;
                    ob.UpdatedDate = DateTime.Now;
                }
                GetUnitOfWork().ObjectiveSubRepository.Update(ob);
            }
            else
            {
                if (weight > 100)
                {
                    throw new Exception("Weight should not be greater then 100");
                }
                if (mainId == Guid.Empty)
                {
                    ObjectiveMain main = new ObjectiveMain()
                    {
                        EmployeeId = CreatedBy
                    };
                    InsertObjectiveMain(main);
                    mainId = main.Id;
                }
                sub.CreatedBy           = CreatedBy;
                sub.CreatedDate         = DateTime.Now;
                sub.ObjectiveMainId     = mainId;
                sub.IsObjectiveApproved = false;
                sub.Status = true;
                sub.Id     = UniqueNumber.GenerateUniqueNumber();
                GetUnitOfWork().ObjectiveSubRepository.Insert(sub);
            }
        }
        private void SaveMedicineIfNew()
        {
            PharmacyDbContext db       = new PharmacyDbContext();
            Medicine          medicine = new Medicine();

            medicine = db.Medicine.FirstOrDefault(a => a.Name == txtMedicine.Text);
            if (medicine != null)
            {
                medicine.Name        = txtMedicine.Text;
                medicine.Id          = UniqueNumber.GenerateUniqueNumber();
                medicine.CreatedBy   = currentUser;
                medicine.CreatedDate = DateTime.Now;
                medicine.GroupId     = GroupFactory.GetGroupId(txtGroup.Text, currentUser);
                medicine.CompanyId   = CompanyFactory.GetCompanyId(txtCompany.Text, currentUser);
                db.Medicine.Add(medicine);
            }
        }