private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                var accounts = context.CustomerAccounts.ToList();
                int accountNo = 0;
                if (accounts.Count() > 0)
                {
                    List<CustomerAccountsReportData> dataList = new List<CustomerAccountsReportData>();
                    List<CustomerAccountsReportDetail> detailsList = new List<CustomerAccountsReportDetail>();
                    foreach (var account in accounts)
                    {
                        accountNo++;
                        var detail = new CustomerAccountsReportDetail();
                        var territory = context.Territories.FirstOrDefault(c => c.TerritoryID == account.TerritoryID);
                        var customer = context.Customers.FirstOrDefault(c => c.CustomerID == account.CustomerID);
                        var product = context.Products.FirstOrDefault(c => c.ProductID == account.ProductID);

                        detail.AccountNumber = Convert.ToString(accountNo);
                        detail.Customer = customer.CompanyName;
                        detail.Discount = account.Discount;
                        detail.Gross = account.Gross;
                        detail.ModeOfPayment = account.ModeOfPayment;
                        detail.NetValue = account.NetValue;
                        detail.Product = product.ProductName;
                        detail.ServiceCharge = account.ServiceCharge;
                        detail.Territory = territory.TerritoryName;
                        detailsList.Add(detail);
                    }
                    dataList.Add(new CustomerAccountsReportData()
                    {
                        ReportHeader = "CUSTOMER ACCOUNTS",
                        ReportTitle = "CUSTOMER ACCOUNTS as of " + DateTime.Now.ToString("MMMM dd, yyyy"),
                        TotalCustomerAccounts = detailsList.Count(),
                        details = detailsList
                    });

                    var report = new CustomerAccountsReportDesign
                    {
                        DataSource = dataList.Distinct(),
                        Name = "CUSTOMER ACCOUNTS as of "
                            + DateTime.Now.ToString("MMMM dd, yyyy")
                    };

                    using (ReportPrintTool printTool = new ReportPrintTool(report))
                    {
                        printTool.ShowRibbonPreviewDialog();
                    }
                }
                else
                {
                    var windows = new Shared.Windows.NoticeWindow();
                    Shared.Windows.NoticeWindow.message = "No data to print.";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
            }
        }
 private void NullMessage()
 {
     var windows = new Shared.Windows.NoticeWindow();
     NoticeWindow.message = "Please select a record.";
     windows.Height = 0;
     windows.Top = screenTopEdge + 8;
     windows.Left = (screenWidth / 2) - (windows.Width / 2);
     if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
     windows.ShowDialog();
 }
        private async void RefreshTable(string str)
        {
            using (var context = new DatabaseContext())
            {
                string message = "";
                busyIndicator.IsBusy = true;
                message = await QueryLoadCustomerAccounts();

                if (message != null)
                {
                    var windows = new Shared.Windows.NoticeWindow();
                    NoticeWindow.message = message;
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }


                if (customerAccountsList.Count() > 0)
                {
                    dcCustomerAccountsList.ItemsSource = customerAccountsList.Where
                        (c => c.AccountNumber.ToLower().Contains(str.ToLower())
                        || c.Customer.ToLower().Contains(str.ToLower())
                        || c.Product.ToLower().Contains(str.ToLower())
                        || c.Territory.ToLower().Contains(str.ToLower())).ToList();
                }
                else
                {
                    dcCustomerAccountsList.ItemsSource = null;

                    var windows = new Shared.Windows.NoticeWindow();
                    NoticeWindow.message = "No customer accounts";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }

                viewCustomerAccounts.BestFitColumns();


                if (customerAccountsList.Count == 0)
                {
                    var windows = new Shared.Windows.NoticeWindow();
                    NoticeWindow.message = "List has no customer accounts.";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
                busyIndicator.IsBusy = false;
            }
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            using (var context= new DatabaseContext())
            {
                var selectedAccount = dcCustomerAccountsList.SelectedItem as CustomerAccountsView;

                if (selectedAccount != null)
                {
                    var account = context.CustomerAccounts.FirstOrDefault(c => c.AccountNumber == selectedAccount.AccountNumber);

                    if (account != null)
                    {
                        var window = new MessageBoxWindow("Are you sure you want to delete this record?");
                        window.Height = 0;
                        window.Top = screenTopEdge + 8;
                        window.Left = (screenWidth / 2) - (window.Width / 2);
                        if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; }
                        window.ShowDialog();

                        if (Variables.yesClicked == true)
                        {
                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd//yyyy");
                            log.Time = DateTime.Now.ToString("HH:mm");
                            log.Description = NotificationWindow.username + " deleted "
                                + selectedAccount.Customer + "'s customer account.";
                            context.Logs.Add(log);

                            context.CustomerAccounts.Remove(account);
                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "Customer account successfully deleted";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();

                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        NullMessage();
                    }
                }
                LoadCustomerAccounts();
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                if (txtAddress.Text != "" && txtTerritoryName.Text != "")
                {
                    if (TerritoryId > 0)
                    {
                        var territory = context.Territories.FirstOrDefault(c => c.TerritoryID == TerritoryId);

                        if (territory != null)
                        {
                            var territoryName = context.Territories.FirstOrDefault
                                (c => c.TerritoryName.ToLower() == txtTerritoryName.Text.ToLower());

                            if (territoryName != null)
                            {
                                if (territory.TerritoryName.ToLower() == territoryName.TerritoryName.ToLower()
                                    && territory.Address.ToLower() == territoryName.Address.ToLower())
                                {
                                    territory.Address = txtAddress.Text;
                                    territory.TerritoryName = txtTerritoryName.Text;
                                    territory.PhoneNo = txtPhoneNo.Text;

                                    var log = new Log();
                                    log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                    log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                    log.Description = NotificationWindow.username + " modified "
                                        + territory.TerritoryName + " territory's details.";
                                    context.Logs.Add(log);

                                    context.SaveChanges();
                                    var windows = new Shared.Windows.NoticeWindow();
                                    Shared.Windows.NoticeWindow.message = "Territory successfully updated";
                                    windows.Height = 0;
                                    windows.Top = screenTopEdge + 8;
                                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                    windows.ShowDialog();
                                }
                                else
                                {
                                    var log = new Log();
                                    log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                    log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                    log.Description = NotificationWindow.username + " failed to modify "
                                        + territory.TerritoryName + " territory's details due to a similar territory is already existing.";
                                    context.Logs.Add(log);
                                    context.SaveChanges();

                                    var windows = new Shared.Windows.NoticeWindow();
                                    Shared.Windows.NoticeWindow.message = "Similar territory detected";
                                    windows.Height = 0;
                                    windows.Top = screenTopEdge + 8;
                                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                    windows.ShowDialog();
                                }
                            }
                        }
                    }
                    else
                    {
                        var territory = context.Territories.FirstOrDefault
                             (c => c.TerritoryName.ToLower() == txtTerritoryName.Text.ToLower()
                                 && c.Address.ToLower() == txtAddress.Text.ToLower() && c.PhoneNo.ToLower() == txtPhoneNo.Text.ToLower());

                        if (territory == null)
                        {
                            territory = new Territory();
                            
                            territory.TerritoryName = txtTerritoryName.Text;
                            territory.Address = txtAddress.Text;
                            territory.PhoneNo = txtPhoneNo.Text;
                            context.Territories.Add(territory);

                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            log.Description = NotificationWindow.username + " created a territory. ("
                                + territory.TerritoryName + ")";
                            context.Logs.Add(log);

                            context.SaveChanges();
                            
                            var windows = new NoticeWindow();
                            NoticeWindow.message = "Territory successfully created";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                        else
                        {
                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            log.Description = NotificationWindow.username + " failed to modify "
                                + territory.TerritoryName + " territory's details due to a similar territory is already existing.";
                            context.Logs.Add(log);
                            context.SaveChanges();

                            var windows = new NoticeWindow();
                            NoticeWindow.message = "Territory already exist";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                    }
                }
                else
                {
                    var windows = new Shared.Windows.NoticeWindow();
                    Shared.Windows.NoticeWindow.message = "Please provide all fields associated with an asterisk(*).";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
            }
        }
示例#6
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                var lead = new Lead();
                var territory = new Territory();

                if(txtCompanyAddress.Text != "" && txtCompanyName.Text != "" 
                        && (cbStatus.Text != "" || cbStatus.Text != null) 
                        && (cbTerritory.Text != "" || cbTerritory.Text != null))
                {
                    if (LeadId > 0)
                    {
                        territory = context.Territories.FirstOrDefault
                            (c => c.TerritoryName.ToLower() == cbTerritory.Text.ToLower());
                        lead = context.Leads.FirstOrDefault(c => c.LeadID == LeadId);

                        if (lead != null)
                        {
                            var leadName = context.Leads.FirstOrDefault(c => c.LeadID == LeadId);

                            if (leadName != null)
                            {
                                if (lead.CompanyName == leadName.CompanyName
                                    && lead.CompanyAddress == leadName.CompanyAddress)
                                {
                                    lead.CompanyAddress = txtCompanyAddress.Text;
                                    lead.CompanyName = txtCompanyName.Text;
                                    lead.Status = cbStatus.Text;
                                    lead.TerritoryID = territory.TerritoryID;

                                    context.SaveChanges();
                                    var windows = new Shared.Windows.NoticeWindow();
                                    Shared.Windows.NoticeWindow.message = "LEAD SUCCESSFULLY UPDATED";
                                    windows.Height = 0;
                                    windows.Top = screenTopEdge + 8;
                                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                    windows.ShowDialog();
                                    DialogResult = false;
                                }
                                else
                                {
                                    var windows = new Shared.Windows.NoticeWindow();
                                    Shared.Windows.NoticeWindow.message = "SIMILAR LEAD DETECTED";
                                    windows.Height = 0;
                                    windows.Top = screenTopEdge + 8;
                                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                    windows.ShowDialog();
                                }
                            }
                        }
                    }
                    else
                    {
                        territory = context.Territories.FirstOrDefault
                            (c => c.TerritoryName.ToLower() == cbTerritory.Text.ToLower());
                        lead = context.Leads.FirstOrDefault
                            (c => c.CompanyName.ToLower() == txtCompanyName.Text.ToLower()
                            && c.CompanyAddress.ToLower() == txtCompanyAddress.Text.ToLower()
                            && c.TerritoryID == territory.TerritoryID);

                        if (lead == null)
                        {
                            lead = new Lead();

                            lead.CompanyAddress = txtCompanyAddress.Text;
                            lead.CompanyName = txtCompanyName.Text;
                            lead.Status = cbStatus.Text;
                            lead.TerritoryID = territory.TerritoryID;

                            context.Leads.Add(lead);
                            context.SaveChanges();
                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "LEAD SUCCESSFULLY CREATED";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                            DialogResult = false;
                        }
                        else
                        {
                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "LEAD ALREADY EXIST";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                    }
                }
                else
                {
                    var windows = new Shared.Windows.NoticeWindow();
                    Shared.Windows.NoticeWindow.message = "PLEASE PROVIDE ALL ASSOCIATED WITH ASTERISKS(*)";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
            }
        }
示例#7
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                var lead = new Lead();
                var territory = new Territory();

                if(txtCompanyAddress.Text != "" && txtCompanyName.Text != "" 
                        && (cbStatus.Text != "" || cbStatus.Text != null) 
                        && (cbTerritory.Text != "" || cbTerritory.Text != null)
                        && (cbMarketingStrategy.Text!="" || cbMarketingStrategy.Text != null))
                {
                    if (LeadId > 0)
                    {
                        #region edit
                        territory = context.Territories.FirstOrDefault
                            (c => c.TerritoryName.ToLower() == cbTerritory.Text.ToLower());
                        lead = context.Leads.FirstOrDefault(c => c.LeadID == LeadId);

                        if (lead != null)
                        {
                            var duplicateName = context.Leads.FirstOrDefault
                                (c => (c.LeadID == lead.LeadID) && 
                                    (c.CompanyName.ToLower() == txtCompanyName.Text.ToLower()));
                            var existingLead = context.Leads.FirstOrDefault
                                (c => c.CompanyName.ToLower() == txtCompanyName.Text.ToLower());

                            if (duplicateName != null || existingLead == null)
                            {
                                var marketingStrategy = context.MarketingStrategies.FirstOrDefault(c => c.Description.ToLower() == cbMarketingStrategy.Text.ToLower());

                                lead.CompanyAddress = txtCompanyAddress.Text;
                                lead.CompanyName = txtCompanyName.Text;
                                lead.Status = cbStatus.Text;
                                lead.TerritoryID = territory.TerritoryID;
                                lead.IsActive = tsActiveCheck.IsChecked.Value;
                                if (marketingStrategy != null) { lead.MarketingStrategyId = marketingStrategy.MarketingStrategyId; }
                                else { lead.MarketingStrategyId = 0; }

                                if (lbLeadsProducts != null)
                                {
                                    foreach (var product in lbLeadsProducts.Items)
                                    {
                                        var productId = context.Products.FirstOrDefault(c => c.ProductName == (string) product);

                                        if (productId != null)
                                        {
                                            var products = context.LeadsProducts.FirstOrDefault(c => c.ProductId == productId.ProductID && c.LeadId == LeadId);

                                            if (products != null)
                                            {
                                                products.LeadId = LeadId;
                                                products.ProductId = productId.ProductID;
                                            }
                                        }
                                    }
                                }

                                var log = new Log();
                                log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                log.Description = NotificationWindow.username + " modifies "
                                    + lead.CompanyName + "'s details.";
                                log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                context.Logs.Add(log);

                                context.SaveChanges();
                                var windows = new NoticeWindow();
                                NoticeWindow.message = "Lead successfully updated";
                                windows.Height = 0;
                                windows.Top = screenTopEdge + 8;
                                windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                windows.ShowDialog();
                            }
                            else
                            {
                                var windows = new NoticeWindow();
                                NoticeWindow.message = "Similar lead detected";
                                windows.Height = 0;
                                windows.Top = screenTopEdge + 8;
                                windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                windows.ShowDialog();

                                var log = new Log();
                                log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                log.Description = NotificationWindow.username + " fails to modify "
                                    + lead.CompanyName + " due to a similar lead is detected.";
                                log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                context.Logs.Add(log);
                                context.SaveChanges();
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region add
                        territory = context.Territories.FirstOrDefault
                            (c => c.TerritoryName.ToLower() == cbTerritory.Text.ToLower());
                        lead = context.Leads.FirstOrDefault
                            (c => c.CompanyName.ToLower() == txtCompanyName.Text.ToLower()
                            && (c.CompanyAddress.ToLower() == txtCompanyAddress.Text.ToLower()
                            || c.TerritoryID == territory.TerritoryID));

                        if (lead == null)
                        {
                            lead = new Lead();

                            var marketingStrategy = context.MarketingStrategies.FirstOrDefault(c => c.Description.ToLower() == cbMarketingStrategy.Text.ToLower());

                            lead.CompanyAddress = txtCompanyAddress.Text;
                            lead.CompanyName = txtCompanyName.Text;
                            lead.Status = cbStatus.Text;
                            lead.TerritoryID = territory.TerritoryID;
                            lead.IsActive = tsActiveCheck.IsChecked.Value;
                            lead.DateAdded = DateTime.Now.ToString("MM/dd/yyyy");
                            if (marketingStrategy != null) { lead.MarketingStrategyId = marketingStrategy.MarketingStrategyId; }
                            else { lead.MarketingStrategyId = 0; }
                            if (lbLeadsProducts != null)
                            {
                                foreach (var product in lbLeadsProducts.Items)
                                {
                                    var productId = context.Products.FirstOrDefault(c => c.ProductName == (string) product);

                                    if (productId != null)
                                    {
                                        var products = context.LeadsProducts.FirstOrDefault(c => c.ProductId == productId.ProductID && c.LeadId == LeadId);

                                        if (products == null)
                                        {
                                            products = new LeadsProduct();

                                            context.LeadsProducts.Add(new LeadsProduct
                                            {
                                                ProductId = productId.ProductID,
                                                LeadId = products.LeadId
                                            });
                                        }
                                    }
                                }
                            }
                            context.Leads.Add(lead);

                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Description = NotificationWindow.username + " creates a new lead. ("
                                + txtCompanyName.Text + ")";
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            context.Logs.Add(log);

                            context.SaveChanges();
                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "Lead successfully created";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                        else
                        {
                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Description = NotificationWindow.username + " fails to create a new lead due to the lead is already existing.";
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            context.Logs.Add(log);
                            context.SaveChanges();

                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "Lead already exists";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                        #endregion
                    }
                }
                else
                {
                    var windows = new NoticeWindow();
                    NoticeWindow.message = "Please provide all boxes labeled with an asterisk(*).";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
            }
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            var windows = new Shared.Windows.NoticeWindow();
            Shared.Windows.NoticeWindow.message = "An activity cannot be deleted.";
            windows.Height = 0;
            windows.Top = screenTopEdge + 8;
            windows.Left = (screenWidth / 2) - (windows.Width / 2);
            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
            windows.ShowDialog();

            //using (var context = new DatabaseContext())
            //{
            //    var selectedActivity = dcLeadActivitiesList.SelectedItem as ActivityView;

            //    if (selectedActivity != null)
            //    {
            //        var activity = context.LeadActivities.FirstOrDefault(c => c.ActivityID == selectedActivity.ActivityId);

            //        if (activity != null)
            //        {
            //            var window = new MessageBoxWindow("Are you sure you want to delete this record?");
            //            window.Height = 0;
            //            window.Top = screenTopEdge + 8;
            //            window.Left = (screenWidth / 2) - (window.Width / 2);
            //            if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; }
            //            window.ShowDialog();

            //            if (Variables.yesClicked == true)
            //            {
            //                if (activity.ActivityDate != null && activity.ActivityTime != null)
            //                {
            //                    context.LeadActivities.Remove(activity);

            //                    var windows = new Shared.Windows.NoticeWindow();
            //                    Shared.Windows.NoticeWindow.message = "Activity successfully deleted";
            //                    windows.Height = 0;
            //                    windows.Top = screenTopEdge + 8;
            //                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
            //                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
            //                    windows.ShowDialog();

            //                    context.SaveChanges();
            //                }
            //                else
            //                {
            //                    var windows = new Shared.Windows.NoticeWindow();
            //                    Shared.Windows.NoticeWindow.message = "Activity is still not done.";
            //                    windows.Height = 0;
            //                    windows.Top = screenTopEdge + 8;
            //                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
            //                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
            //                    windows.ShowDialog();
            //                }
            //            }
            //        }
            //    }
            //    else
            //    {
            //        NullMessage();
            //    }
            //    LoadMethod(txtSearch.Text);
            //}
        }
示例#9
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                var selectedEmployee = dcEmployeesList.SelectedItem as EmployeeView;

                if (selectedEmployee != null)
                {
                    var employee = context.Employees.FirstOrDefault(c => c.EmployeeId == selectedEmployee.EmployeeId);

                    if (employee != null)
                    {
                        var window = new MessageBoxWindow("Are you sure you want to delete this record?");
                        window.Height = 0;
                        window.Top = screenTopEdge + 8;
                        window.Left = (screenWidth / 2) - (window.Width / 2);
                        if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; }
                        window.ShowDialog();

                        if (Variables.yesClicked == true)
                        {
                            context.Employees.Remove(employee);

                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "LEAD SUCCESSFULLY DELETED";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();

                            context.SaveChanges();
                        }
                        else
                        {
                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "DELETION CANCELLED";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                    }
                }
                LoadEmployees();
            }
        }
示例#10
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                var selectedterritories = dcTerritoryList.SelectedItem as TerritoryView;

                if (selectedterritories != null)
                {
                    var terri = context.Territories.FirstOrDefault(c => c.TerritoryID == selectedterritories.TerritoryID);

                    if (terri != null)
                    {
                        var window = new MessageBoxWindow("Are you sure you want to delete this record?");
                        window.Height = 0;
                        window.Top = screenTopEdge + 8;
                        window.Left = (screenWidth / 2) - (window.Width / 2);
                        if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; }
                        window.ShowDialog();

                        if (Variables.yesClicked == true)
                        {
                            context.Territories.Remove(terri);

                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            log.Description = NotificationWindow.username + " deleted "
                                + selectedterritories.TerritoryName + " territory.";
                            context.Logs.Add(log);

                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "Territory successfully deleted";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();

                            context.SaveChanges();
                            LoadMethod(txtSearch.Text);
                        }
                    }
                }
            }
        }
示例#11
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                var sale = new SalesStage();

                if (txtRankNo.Text != "" && txtSalesStageName.Text != "")
                {
                    if (SalesStageId > 0)
                    {
                        var sales = context.SalesStages.FirstOrDefault(c => c.SalesStageID == SalesStageId);

                        if (sales != null)
                        {
                            var stagename = context.SalesStages.FirstOrDefault(c => c.SalesStageName == txtSalesStageName.Text);

                            if (stagename != null)
                            {
                                if (sales.SalesStageName.ToLower() == stagename.SalesStageName.ToLower()
                                    && sales.RankNo == stagename.RankNo)
                                {
                                    sales.RankNo = Convert.ToInt32(txtRankNo.Text);
                                    sales.SalesStageName = txtSalesStageName.Text;

                                    var log = new Log();
                                    log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                    log.Description = NotificationWindow.username + " modified "
                                        + sales.SalesStageName + "'s details.";
                                    log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                    context.Logs.Add(log);

                                    context.SaveChanges();
                                    var windows = new NoticeWindow();
                                    NoticeWindow.message = "Sales Stage successfully updated";
                                    windows.Height = 0;
                                    windows.Top = screenTopEdge + 8;
                                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                    windows.ShowDialog();
                                }

                                else
                                {
                                    var log = new Log();
                                    log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                    log.Description = NotificationWindow.username + " failed to modify "
                                        + sales.SalesStageName
                                        + "'s details due to a similar stage is already existing.";
                                    log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                    context.Logs.Add(log);
                                    context.SaveChanges();

                                    var windows = new NoticeWindow();
                                    NoticeWindow.message = "Similar Stage detected";
                                    windows.Height = 0;
                                    windows.Top = screenTopEdge + 8;
                                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                    windows.ShowDialog();
                                }
                            }
                            else
                            {
                                sales.RankNo = Convert.ToInt32(txtRankNo.Text);
                                sales.SalesStageName = txtSalesStageName.Text;

                                var log = new Log();
                                log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                log.Description = NotificationWindow.username + " modified "
                                    + sales.SalesStageName + "'s details.";
                                log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                context.Logs.Add(log);

                                context.SaveChanges();
                                var windows = new NoticeWindow();
                                NoticeWindow.message = "Sales Stage successfully updated";
                                windows.Height = 0;
                                windows.Top = screenTopEdge + 8;
                                windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                windows.ShowDialog();
                            }
                        }
                    }

                    else
                    {
                        var Stages = context.SalesStages.FirstOrDefault
                            (c => c.SalesStageName.ToLower() == txtSalesStageName.Text.ToLower());

                        if (Stages == null)
                        {
                            Stages = new SalesStage();
                            Stages.SalesStageName = txtSalesStageName.Text;
                            Stages.RankNo =Convert.ToInt32 (txtRankNo.Text);

                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Description = NotificationWindow.username + " created a sales stage. ("
                                + txtSalesStageName.Text + ")";
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            context.Logs.Add(log);

                            context.SalesStages.Add(Stages);
                            context.SaveChanges();
                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "Sale Stage successfully created";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                        else
                        {
                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Description = NotificationWindow.username
                                + " failed to create due to a similar stage is already existing.";
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            context.Logs.Add(log);
                            context.SaveChanges();

                            var windows = new NoticeWindow();
                            NoticeWindow.message = "Sale Stage already exists";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                    }
                }

                else
                {
                    var windows = new NoticeWindow();
                    NoticeWindow.message = "Please provide all fields associated with an asterisk(*).";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }

            }
        }
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                int customerNo = 0;
                if (customersList.Count() > 0)
                {
                    List<CustomersReportData> dataList = new List<CustomersReportData>();
                    List<CustomersReportDetail> detailsList = new List<CustomersReportDetail>();
                    foreach (var customer in customersList.OrderBy(c => c.CustomerID))
                    {
                        customerNo++;
                        var detail = new CustomersReportDetail();
                        var lead = context.Leads.FirstOrDefault
                            (c => c.CompanyName.ToLower() == customer.CompanyName.ToLower());

                        detail.CompanyAddress = customer.CompanyAddress;
                        detail.CompanyName = customer.CompanyName;
                        detail.CustomerID = customerNo;
                        detail.DateSigned = customer.DateSigned;
                        detail.Email = customer.Email;
                        if (lead != null) { detail.FromLead = "FROM LEAD"; } else { detail.FromLead = ""; }
                        detail.PhoneNo = customer.PhoneNo;
                        detail.Website = customer.Website;
                        detailsList.Add(detail);
                    }
                    dataList.Add(new CustomersReportData()
                    {
                        ReportHeader = "CUSTOMERS",
                        ReportTitle = "CUSTOMERS as of " + DateTime.Now.ToString("MMMM dd, yyyy"),
                        TotalCustomers = detailsList.Count(),
                        details = detailsList
                    });

                    var report = new CustomersReportDesign
                    {
                        DataSource = dataList.Distinct(),
                        Name = "CUSTOMERS as of "
                            + DateTime.Now.ToString("MMMM dd, yyyy")
                    };

                    using (ReportPrintTool printTool = new ReportPrintTool(report))
                    {
                        printTool.ShowRibbonPreviewDialog();
                    }
                }
                else
                {
                    var windows = new Shared.Windows.NoticeWindow();
                    Shared.Windows.NoticeWindow.message = "No data to print.";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
            }
        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            using (var context= new DatabaseContext())
            {
                var selectedCustomer = dcCustomersList.SelectedItem as CustomersView;

                if (selectedCustomer != null)
                {
                    var customer = context.Customers.FirstOrDefault(c => c.CustomerID == selectedCustomer.CustomerID);

                    if (customer != null)
                    {
                        var window = new MessageBoxWindow("Are you sure you want to delete this record?");
                        window.Height = 0;
                        window.Top = screenTopEdge + 8;
                        window.Left = (screenWidth / 2) - (window.Width / 2);
                        if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; }
                        window.ShowDialog();

                        if (Variables.yesClicked == true)
                        {
                            context.Customers.Remove(customer);
                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "Customer successfully deleted";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();

                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        NullMessage();
                    }
                }
                LoadCustomers();
            }
        }
示例#14
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (EmployeeId > 0)
            {
                using (var context = new DatabaseContext())
                {
                    var employee = context.Employees.FirstOrDefault(c => c.EmployeeId == EmployeeId);

                    if (employee != null)
                    {
                        employee.Address = txtAddress.Text;
                        employee.EmailAddress = txtEmailAddress.Text;
                        employee.EmployeeId = Convert.ToInt32(txtEmployeeId.Text);
                        employee.FaxNo = txtFaxNo.Text;
                        employee.FirstName = txtFirstName.Text;
                        employee.LastName = txtLastName.Text;
                        employee.MiddleName = txtMiddleName.Text;
                        employee.PhoneNo = txtPhoneNo.Text;
                        employee.Position = txtPosition.Text;
                        employee.Territory = cbTerritory.Text;
                            
                        var employeeName = context.Employees.FirstOrDefault
                            (c => c.FirstName.ToLower() == txtFirstName.Text.ToLower() && 
                            c.MiddleName.ToLower() == txtMiddleName.Text.ToLower() &&
                            c.LastName.ToLower() == txtLastName.Text.ToLower());

                        if (employeeName == null)
                        {
                            context.SaveChanges();

                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "Successfully updated";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();

                            this.Close();
                        }
                    }
                }
            }
            else
            {
                using (var context = new DatabaseContext())
                {
                    var employeeName = context.Employees.FirstOrDefault
                                (c => c.FirstName.ToLower() == txtFirstName.Text.ToLower() && 
                                c.MiddleName.ToLower() == txtMiddleName.Text.ToLower() &&
                                c.LastName.ToLower() == txtLastName.Text.ToLower());

                    if (employeeName == null)
                    {
                        var employee = new Employee();
                        employee.Address = txtAddress.Text;
                        employee.EmailAddress = txtEmailAddress.Text;
                        employee.EmployeeId = Convert.ToInt32(txtEmployeeId.Text);
                        employee.FaxNo = txtFaxNo.Text;
                        employee.FirstName = txtFirstName.Text;
                        employee.LastName = txtLastName.Text;
                        employee.MiddleName = txtMiddleName.Text;
                        employee.PhoneNo = txtPhoneNo.Text;
                        employee.Position = txtPosition.Text;
                        employee.Territory = cbTerritory.Text;

                        context.Employees.Add(employee);
                        context.SaveChanges();

                        var windows = new Shared.Windows.NoticeWindow();
                        Shared.Windows.NoticeWindow.message = "Employee succesfully created";
                        windows.Height = 0;
                        windows.Top = screenTopEdge + 8;
                        windows.Left = (screenWidth / 2) - (windows.Width / 2);
                        if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                        windows.ShowDialog();

                        this.Close();
                    }
                    else
                    {
                        var windows = new Shared.Windows.NoticeWindow();
                        Shared.Windows.NoticeWindow.message = "A name similar to this employee is already existing.";
                        windows.Height = 0;
                        windows.Top = screenTopEdge + 8;
                        windows.Left = (screenWidth / 2) - (windows.Width / 2);
                        if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                        windows.ShowDialog();
                    }
                }
            }
        }
示例#15
0
         private async void RefreshTable(string str)
        {
            using (var context = new DatabaseContext())
            {
                string message = "";
                busyIndicator.IsBusy = true;
                message = await QueryLoadSalesStages();

                 if (message != null)
                {
                    var windows = new Shared.Windows.NoticeWindow();
                    NoticeWindow.message = message;
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
                

                    dcSalesStagesList.ItemsSource = salessatageList.Where
                        (c => (c.SalesStageName.ToLower().Contains(txtSearch.Text.ToLower()))).
                        OrderBy(c => c.RankNo).ToList();
                           
                   viewSalesStages.BestFitColumns();


                if (salessatageList.Count == 0)
                {
                    var windows = new Shared.Windows.NoticeWindow();
                    NoticeWindow.message = "List has no Sales Stages.";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
                busyIndicator.IsBusy = false;
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                var prodcat = new ProductCategory();

                if (txtCategoryName.Text != "" && txtCategoryName.Text != null)
                {
                    if (ProdCategoryId > 0)
                    {
                        var category = context.ProductCategories.FirstOrDefault(c => c.CategoryID == ProdCategoryId);

                        if (category != null)
                        {
                            var duplicateCategory = context.ProductCategories.FirstOrDefault
                                (c => c.CategoryID == category.CategoryID &&
                                    c.CategoryName.ToLower() == txtCategoryName.Text.ToLower());
                            var existingCategory = context.ProductCategories.FirstOrDefault
                                (c => c.CategoryName.ToLower() == txtCategoryName.Text.ToLower());

                            if (duplicateCategory != null || existingCategory == null)
                            {
                                category.CategoryID = Convert.ToInt32(txtCategoryId.Text);
                                category.CategoryName = txtCategoryName.Text;

                                var log = new Log();
                                log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                log.Description = NotificationWindow.username + " modifies "
                                    + category.CategoryName + "'s product category details.";
                                log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                context.Logs.Add(log);

                                context.SaveChanges();
                                var windows = new NoticeWindow();
                                NoticeWindow.message = "Product category successfully updated";
                                windows.Height = 0;
                                windows.Top = screenTopEdge + 8;
                                windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                windows.ShowDialog();
                            }
                            else
                            {
                                var log = new Log();
                                log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                log.Description = NotificationWindow.username + " fails to modify "
                                    + category.CategoryName
                                    + "'s details due to a similar product category is already existing.";
                                log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                context.Logs.Add(log);
                                context.SaveChanges();

                                var windows = new NoticeWindow();
                                NoticeWindow.message = "Similar product category detected";
                                windows.Height = 0;
                                windows.Top = screenTopEdge + 8;
                                windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                windows.ShowDialog();
                            }
                        }
                    }
                    else
                    {
                        var category = context.ProductCategories.FirstOrDefault
                            (c => c.CategoryName.ToLower() == txtCategoryName.Text.ToLower());

                        if (category == null)
                        {
                            category = new ProductCategory();
                            category.CategoryName = txtCategoryName.Text;
                            context.ProductCategories.Add(category);

                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Description = NotificationWindow.username + " creates a new product category. ("
                                + txtCategoryName.Text + ")";
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            context.Logs.Add(log);

                            context.SaveChanges();
                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "Product category successfully created";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                        else
                        {
                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Description = NotificationWindow.username
                                + " fails to create due to a similar product category is already existing.";
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            context.Logs.Add(log);
                            context.SaveChanges();

                            var windows = new NoticeWindow();
                            NoticeWindow.message = "Product category already exists";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                    }
                }
                else
                {
                    var windows = new NoticeWindow();
                    NoticeWindow.message = "Please provide all boxes labeled with an asterisk(*).";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new DatabaseContext())
            {
                var mark = new MarketingStrategy();

                if (txtMarketingStrategyName.Text != "" && txtMarketingStrategyName.Text != null)
                {
                    if (MarketingStrategiesId > 0)
                    {
                        var starts = context.MarketingStrategies.FirstOrDefault(c => c.MarketingStrategyId == MarketingStrategiesId);

                        if (starts != null)
                        {
                            var startsname = context.MarketingStrategies.FirstOrDefault(c => c.Description == txtMarketingStrategyName.Text);

                            if (startsname != null)
                            {
                                if (starts.Description.ToLower() == startsname.Description.ToLower())
                                {
                                    starts.Description = txtMarketingStrategyName.Text;

                                    var log = new Log();
                                    log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                    log.Description = NotificationWindow.username + " modifies "
                                        + starts.Description + "'s details.";
                                    log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                    context.Logs.Add(log);

                                    context.SaveChanges();
                                    var windows = new NoticeWindow();
                                    NoticeWindow.message = "Marketing strategy successfully updated";
                                    windows.Height = 0;
                                    windows.Top = screenTopEdge + 8;
                                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                    windows.ShowDialog();
                                }
                                else
                                {
                                    var log = new Log();
                                    log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                    log.Description = NotificationWindow.username + " fails to modify "
                                        + starts.Description
                                        + "'s details due to a similar strategy is already existing.";
                                    log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                    context.Logs.Add(log);
                                    context.SaveChanges();

                                    var windows = new NoticeWindow();
                                    NoticeWindow.message = "Similar marketing strategy detected";
                                    windows.Height = 0;
                                    windows.Top = screenTopEdge + 8;
                                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                    windows.ShowDialog();
                                }
                            }
                            else
                            {
                                starts.Description = txtMarketingStrategyName.Text;

                                var log = new Log();
                                log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                                log.Description = NotificationWindow.username + " modifies "
                                    + starts.Description + "'s details.";
                                log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                                context.Logs.Add(log);

                                context.SaveChanges();
                                var windows = new NoticeWindow();
                                NoticeWindow.message = "Marketing strategy successfully updated";
                                windows.Height = 0;
                                windows.Top = screenTopEdge + 8;
                                windows.Left = (screenWidth / 2) - (windows.Width / 2);
                                if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                                windows.ShowDialog();
                            }
                        }
                    }
                    else
                    {
                        var strats = context.MarketingStrategies.FirstOrDefault
                            (c => c.Description.ToLower() == txtMarketingStrategyName.Text.ToLower());

                        if (strats == null)
                        {
                            strats = new MarketingStrategy();
                            strats.Description = txtMarketingStrategyName.Text;

                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Description = NotificationWindow.username + " creates a new marketing strategy. ("
                                + txtMarketingStrategyName.Text + ")";
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            context.Logs.Add(log);

                            context.MarketingStrategies.Add(strats);
                            context.SaveChanges();
                            var windows = new Shared.Windows.NoticeWindow();
                            Shared.Windows.NoticeWindow.message = "Marketing strategy successfully created";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                        else
                        {
                            var log = new Log();
                            log.Date = DateTime.Now.ToString("MM/dd/yyyy");
                            log.Description = NotificationWindow.username
                                + " failed to create due to a similar strategy is already existing.";
                            log.Time = DateTime.Now.ToString("hh:mm:ss tt");
                            context.Logs.Add(log);
                            context.SaveChanges();

                            var windows = new NoticeWindow();
                            NoticeWindow.message = "Marketing strategy already exists";
                            windows.Height = 0;
                            windows.Top = screenTopEdge + 8;
                            windows.Left = (screenWidth / 2) - (windows.Width / 2);
                            if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                            windows.ShowDialog();
                        }
                    }
                }
                else
                {
                    var windows = new NoticeWindow();
                    NoticeWindow.message = "Please provide all boxes labeled with an asterisk(*).";
                    windows.Height = 0;
                    windows.Top = screenTopEdge + 8;
                    windows.Left = (screenWidth / 2) - (windows.Width / 2);
                    if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; }
                    windows.ShowDialog();
                }
            }
        }