示例#1
0
        public ObservableCollection<CustomerM> GetAllCustomers()
        {
            ObservableCollection<CustomerM> customers = new ObservableCollection<CustomerM>();
            using (PhoneShopdbEntities ctx = new PhoneShopdbEntities())
            {

                var c = ctx.Customers.ToList();

                foreach (var item in c)
                {
                    CustomerM customer = new CustomerM();
                    customer.Id = (int)item.Id;
                    customer.Name = (string)item.Name;
                    customer.NIC = (string)item.NIC;
                    customer.Email = (string)item.Email;

                    var t = ctx.TelephoneNumbers.Where(x => x.Customer_Id == item.Id).ToList();
                    foreach (var t1 in t)
                    {
                        TelephoneNumberM tel = new TelephoneNumberM();
                        tel.Id = t1.Id;
                        tel.CustomerId = (int)t1.Customer_Id;
                        tel.IsHome = (bool)t1.IsHome;
                        tel.TelNo = t1.TelNo;
                        customer.TelephoneNumbers.Add(tel);
                    }

                    customers.Add(customer);
                }
            }
            return customers;
        }
示例#2
0
        public ObservableCollection<TelephoneNumberM> getTelephoneNumberByCustomerId(int customerId)
        {
            ObservableCollection<TelephoneNumberM> tels = new ObservableCollection<TelephoneNumberM>();

            using (PhoneShopdbEntities e = new PhoneShopdbEntities())
            {
                TelephoneNumberM tel = new TelephoneNumberM();
                var t = e.TelephoneNumbers.Where(a => a.Customer_Id == customerId).ToList();

                foreach (var item in t)
                {
                    tel.Id = (int)item.Id;
                    tel.TelNo = (string)item.TelNo;
                    tel.IsHome = (bool)item.IsHome;
                    tel.CustomerId = (int)item.Customer_Id;
                    tels.Add(tel);
                }
            }

            return tels;
        }
        private void SaveJobBtnClicked(object sender, RoutedEventArgs e)
        {
            float advancedPavemnt = 0;
            if (nicNoCBox.Text == null || nicNoCBox.Text.Trim() == "") { nicNoCBox.Focus(); return; }
            else if (customrNameTxtBox.Text == null || customrNameTxtBox.Text.Trim() == "") { customrNameTxtBox.Focus(); return; }
            else if (phoneBrandNamesCB.Text == null || phoneBrandNamesCB.Text.Trim() == "") { phoneBrandNamesCB.Focus(); return; }
            else if (phoneModelsCB.Text == null || phoneModelsCB.Text.Trim() == "") { phoneModelsCB.Focus(); return; }
            else if ((bool)isPhoneChkBox.IsChecked && (emiNoTxtBox.Text == null || emiNoTxtBox.Text.Trim() == "")) { emiNoTxtBox.Focus(); return; }
            else if (advancePaymentTxtBox.Text != "" && !float.TryParse(advancePaymentTxtBox.Text.Trim(), out advancedPavemnt)) { advancePaymentTxtBox.Focus(); return; }

            DetailedJobModelM job = new DetailedJobModelM();

            job.Customer.Name = customrNameTxtBox.Text.Trim();
            job.Customer.NIC = nicNoCBox.Text.Trim();
            job.Customer.Email = emailTxtBox.Text.Trim();
            if (mobileNoTxtBox.Text.Trim() != "")
            {
                TelephoneNumberM mobile = new TelephoneNumberM();
                mobile.TelNo = mobileNoTxtBox.Text.Trim();
                mobile.IsHome = false;
                job.Customer.TelephoneNumbers.Add(mobile);
            }
            if (landNoTxtBox.Text.Trim() != "")
            {
                TelephoneNumberM home = new TelephoneNumberM();
                home.TelNo = landNoTxtBox.Text.Trim();
                home.IsHome = true;
                job.Customer.TelephoneNumbers.Add(home);
            }

            job.PhoneModel.BrandName = phoneBrandNamesCB.Text.Trim();
            job.PhoneModel.SelectedPhoneModel.ModelNumber = phoneModelsCB.Text.Trim();
            //job.PhoneModel.SelectedPhoneModel.ImageURI = //add uri

            job.Job.JobNumber = jobNoTxtBox.Text.Trim();
            job.Job.JobDiscription = new TextRange(jobNoteTxtBox.Document.ContentStart, jobNoteTxtBox.Document.ContentEnd).Text.Trim();
            job.Job.OtherDiscription = new TextRange(otherJobDetailTxtBox.Document.ContentStart, otherJobDetailTxtBox.Document.ContentEnd).Text.Trim();
            job.Job.IsCompleted = false;
            job.Job.AdvancePavement = advancedPavemnt;

            if ((bool)isPhoneChkBox.IsChecked)
            {
                DeviceM phone = new DeviceM();
                phone.IsPhone = true;
                phone.Discription = "Phone";
                phone.EmiNumber = emiNoTxtBox.Text.Trim();
                job.DeviceOrAccaccessories.Add(phone);
            }
            if ((bool)isBatteryChkBox.IsChecked)
            {
                DeviceM battery = new DeviceM();
                battery.IsPhone = false;
                battery.Discription = "Battery";
                job.DeviceOrAccaccessories.Add(battery);
            }
            if ((bool)isMemoryChkBox.IsChecked)
            {
                DeviceM memory = new DeviceM();
                memory.IsPhone = false;
                memory.Discription = "Memory";
                job.DeviceOrAccaccessories.Add(memory);
            }
            if ((bool)isSimChkBox.IsChecked)
            {
                DeviceM sim = new DeviceM();
                sim.IsPhone = false;
                sim.Discription = "Sim";
                job.DeviceOrAccaccessories.Add(sim);
            }
            if ((bool)isBackCoverChkBox.IsChecked)
            {
                DeviceM backCover = new DeviceM();
                backCover.IsPhone = false;
                backCover.Discription = "Back Cover";
                job.DeviceOrAccaccessories.Add(backCover);
            }
            if (otherAccessoryTxtBox.Text.Trim() != "")
            {
                DeviceM backCover = new DeviceM();
                backCover.IsPhone = false;
                backCover.Discription = otherAccessoryTxtBox.Text.Trim();
                job.DeviceOrAccaccessories.Add(backCover);
            }

            if (ProgramDataModel.ProgramDataModelInstance.AddNewJob(job))
            {
                MessageBox.Show("Job is added successfully");
                ClearAllView();
            }
        }