示例#1
0
        public void DetailedJobModelTest()
        {
            DetailedJobModelM job = new DetailedJobModelM();
            CustomerM c = new CustomerM();
            c.Name = "Jayendrak";
            c.NIC = "883481918v";
            c.Email = "*****@*****.**";
            job.Customer = c;

            CRUDManager crudm = new CRUDManager();

            bool b = crudm.AddNewJobDetailed(job);
        }
示例#2
0
        public bool AddNewJobDetailed(DetailedJobModelM job)
        {
            using (PhoneShopdbEntities ctx = new PhoneShopdbEntities())
            {
                Customer customer = ctx.Customers.Where(x => x.NIC == job.Customer.NIC).FirstOrDefault();
                if (customer == null)
                {
                    customer = new Customer();
                    customer.Name = job.Customer.Name;
                    customer.NIC = job.Customer.NIC;
                    customer.Email = job.Customer.Email;
                    ctx.Customers.Add(customer);
                }
                else
                {
                    customer = GetCustomerByNIC(job.Customer.NIC);
                    customer.Name = job.Customer.Name;
                    customer.Email = job.Customer.Email;
                }

                var telNums = ctx.TelephoneNumbers.Where(x => x.Customer_Id == customer.Id).ToList();
                TelephoneNumber home = null;
                TelephoneNumber mobile = null;

                foreach (var item in job.Customer.TelephoneNumbers)
                {
                    if (item.IsHome)
                    {
                        home = telNums.Where(x => x.IsHome == true).FirstOrDefault();
                        if (home == null)
                        {
                            home = new TelephoneNumber();
                            home.Customer_Id = customer.Id;
                            home.IsHome = item.IsHome;
                            home.TelNo = item.TelNo;
                            ctx.TelephoneNumbers.Add(home);
                        }
                        else
                        {
                            home.TelNo = item.TelNo;
                        }
                    }
                    else
                    {
                        mobile = telNums.Where(x => x.IsHome == false).FirstOrDefault();
                        if (mobile == null)
                        {
                            mobile = new TelephoneNumber();
                            mobile.Customer_Id = customer.Id;
                            mobile.IsHome = item.IsHome;
                            mobile.TelNo = item.TelNo;
                            ctx.TelephoneNumbers.Add(mobile);
                        }
                        else
                        {
                            mobile.TelNo = item.TelNo;
                        }
                    }
                }

                PhoneBrand brand = ctx.PhoneBrands.Where(x => x.BrandName == job.PhoneModel.BrandName).FirstOrDefault();
                PhoneModel model = null;
                if (brand == null)
                {
                    brand = new PhoneBrand();
                    brand.BrandName = job.PhoneModel.BrandName;
                    ctx.PhoneBrands.Add(brand);

                    model = new PhoneModel();
                    model.Brand_Id = brand.Id;
                    model.ModelNumber = job.PhoneModel.SelectedPhoneModel.ModelNumber;
                    model.ImageURI = job.PhoneModel.SelectedPhoneModel.ImageURI;

                    ctx.PhoneModels.Add(model);
                }
                else
                {
                    model = ctx.PhoneModels.Where(x => x.ModelNumber == job.PhoneModel.SelectedPhoneModel.ModelNumber).FirstOrDefault();
                    if (model == null)
                    {
                        model = new PhoneModel();
                        model.Brand_Id = (int)brand.Id;
                        model.ModelNumber = job.PhoneModel.SelectedPhoneModel.ModelNumber;
                        model.ImageURI = job.PhoneModel.SelectedPhoneModel.ImageURI;
                        ctx.PhoneModels.Add(model);
                    }
                    else
                    {
                        model.ImageURI = job.PhoneModel.SelectedPhoneModel.ImageURI;
                    }

                    //model.ImageURI = job.PhoneModel.SelectedPhoneModel.ImageURI;
                }

                Job newJob = new Job();
                newJob.Customer_Id = customer.Id;
                newJob.IsCompleted = false;
                newJob.IsDevice = job.DeviceOrAccaccessories.Count == 0 ? false : true;
                newJob.JobDiscription = job.Job.JobDiscription;
                newJob.JobNo = job.Job.JobNumber;
                newJob.OtherDiscription = job.Job.OtherDiscription;
                newJob.PhoneModel_Id = model.Id;
                //advanced pavement
                ctx.Jobs.Add(newJob);

                foreach (var item in job.DeviceOrAccaccessories)
                {
                    Device d = new Device();
                    d.Job_Id = newJob.Id;
                    if (item.IsPhone)
                    {
                        d.IsPhone = true;
                        d.EmiNumber = item.EmiNumber;
                    }
                    d.Discription = item.Discription;
                    ctx.Devices.Add(d);
                }

                ctx.SaveChanges();
            }
            return false;
        }
示例#3
0
        internal ObservableCollection<DetailedJobModelM> GetAllJobsWithAllDetails()
        {
            ObservableCollection<DetailedJobModelM> jobs = new ObservableCollection<DetailedJobModelM>();

            //using (PhoneShopdbEntities e = new PhoneShopdbEntities())
            //{
            //    var jobList = e.Jobs.ToList();

            //    foreach (var item in jobList)
            //    {
            //        DetailedJobModelM model = new DetailedJobModelM();

            //        model.Job.Id = item.Id;
            //        model.Job.JobNumber= item.JobNo;
            //        model.Job.CustomerId =  (int)item.Customer_Id;
            //        model.Job.PhoneModelId = (int)item.PhoneModel_Id;
            //        model.Job.IsCompleted = (bool)item.IsCompleted;
            //        model.Job.HasDevice = (bool)item.IsDevice;
            //        model.Job.JobDiscription = item.JobDiscription;
            //        model.Job.OtherDiscription = item.OtherDiscription;
            //        //model.Job.AdvancePavement

            //        #region get customer

            //        var customer = e.Customers.Where(x => x.Id == item.Customer_Id).FirstOrDefault();
            //        model.Customer = new CustomerM()
            //        {
            //            Id = customer.Id,
            //            Name = customer.Name,
            //            Email = customer.Email,
            //            NIC = customer.Email,
            //        };
            //        var telephones = e.TelephoneNumbers.Where(x => x.Customer_Id == customer.Id).ToList();
            //        foreach (var number in telephones)
            //        {
            //            model.Customer.TelephoneNumbers.Add(new TelephoneNumberM()
            //            {
            //                Id = number.Id,
            //                CustomerId = customer.Id,
            //                IsHome = (bool)number.IsHome,
            //                TelNo = number.TelNo
            //            });
            //        }

            //        #endregion

            //        #region get phone model
            //        var phoneModel = e.PhoneModels.Where(x => x.Id == item.PhoneModel_Id).FirstOrDefault();
            //        model.PhoneModel = new DetailedPhoneModelM()
            //                    {
            //                        Id = phoneModel.Id,
            //                        BrandName = phoneModel.PhoneBrand,

            //                    }

            //        #endregion

            //    }

            //}

            DetailedJobModelM job = new DetailedJobModelM();
            job.Job = new JobM() { JobNumber = "PS - 0001"};
            job.Customer = new CustomerM() { Name = "Jayendra"};

            jobs.Add(job);

            DetailedJobModelM job1 = new DetailedJobModelM();
            job1.Job = new JobM() { JobNumber = "PS - 0001" };
            job1.Customer = new CustomerM() { Name = "Jayendra" };

            jobs.Add(job1);

            return jobs;
        }
        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();
            }
        }
示例#5
0
        public async Task<DetailedJobModelM> LoadDetailedJob()//int jobId
        {
            DetailedJobModelM job = new DetailedJobModelM();
            job.Job = new JobM() { JobNumber = "PS - 0001" };
            job.Customer = new CustomerM() { Name = "Jayendra" };

            return job;
        }
示例#6
0
        public bool AddNewJob(DetailedJobModelM job)
        {
            crudManager.getTelephoneNumberByCustomerId(4);
            if (crudManager.AddNewJobDetailed(job)) 
            {

            }
            return false;
        }