private async void RefreshTable(string str) { using (var context = new DatabaseContext()) { string message = ""; busyIndicator.IsBusy = true; message = await QueryLoadUsers(); if (message != null) { var windows = new 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 (usersList.Count() > 0) { dcUsersList.ItemsSource = usersList.Where(c => c.UserAccountId.ToLower().Contains(str.ToLower()) || c.EmployeeName.ToLower().Contains(str.ToLower())).OrderBy(c => c.UserAccountId).ToList(); viewUser.BestFitColumns(); } else { var windows = new NoticeWindow(); NoticeWindow.message = "List has no 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(); } busyIndicator.IsBusy = false; } }
private void btnOK_Click(object sender, RoutedEventArgs e) { if (listEmployees.SelectedItem != null) { selectedEmployee = listEmployees.SelectedItem.ToString(); Variables.yesClicked = true; var frame = DevExpress.Xpf.Core.Native.LayoutHelper.FindParentObject<NavigationFrame>(this); frame.BackNavigationMode = BackNavigationMode.PreviousScreen; frame.GoBack(); AgentsForm.isSelectFinish = true; } else { var window = new NoticeWindow(); NoticeWindow.message = "Please select a row."; window.Height = 0; window.Top = Application.Current.MainWindow.Top + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); } }
private async void Refresh(string searchVal1, string searchVal2) { busyIndicator.IsBusy = true; string message = ""; if (searchVal1 != "" && searchVal2 != "") { message = await QueryValidateUser(searchVal1, searchVal2); } else { message = "Please input required fields."; } busyIndicator.IsBusy = false; if (message != null) { var window = new NoticeWindow(); NoticeWindow.message = message; window.Height = 0; window.Top = screenTopEdge + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); using (var context = new DatabaseContext()) { var log = new Log(); log.Date = DateTime.Now.ToString("MM/dd/yyyy"); log.Time = DateTime.Now.ToString("hh:mm:ss tt"); log.Description = "An unknown user tries to log in with the username " + txtUsername.Text + "."; context.Logs.Add(log); context.SaveChanges(); } if (txtUsername.Text != null && txtUsername.Text != "") { txtPassword.Text = ""; txtPassword.Focus(); } else { txtUsername.Focus(); } } else { using (var context = new DatabaseContext()) { var user = context.UserAccounts.FirstOrDefault(c => c.UserAccountId == searchVal1); var employee = context.Employees.FirstOrDefault(c => c.EmployeeId == user.EmployeeId); Variables.Name = employee.FirstName + " " + employee.MiddleName + " " + employee.LastName; Variables.ULastName = employee.LastName; Variables.UFirstName = employee.FirstName; Variables.UEmpNo = txtUsername.Text; Variables.CustomerServiceAccess = user.CustomerServiceAccess; Variables.LeadManagementAccess = user.LeadManagementAccess; Variables.TaskManagementAccess = user.TaskManagementAccess; Variables.IsAdmin = user.IsAdmin; btnOK.IsEnabled = false; btnExit.IsEnabled = false; txtUsername.IsReadOnly = true; txtPassword.IsReadOnly = true; var windows = new NotificationWindow(); NotificationWindow.username = Variables.UFirstName + " " + Variables.ULastName; windows.Height = 0; windows.Top = screenTopEdge + 8; windows.Left = (screenWidth / 2) - (windows.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; } windows.ShowDialog(); MainView.Username = txtUsername.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 + " logs in on " + DateTime.Now.ToString("MMMM d, yyyy") + " at " + DateTime.Now.ToString("HH:mm") + "."; context.Logs.Add(log); context.SaveChanges(); var frame = DevExpress.Xpf.Core.Native.LayoutHelper.FindParentObject<NavigationFrame>(this); MainView page = new MainView(); frame.Navigate(page); } } }
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 btnSave_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { if ((txtAddress.Text != null && txtAddress.Text != "") && (txtEmail.Text != null && txtEmail.Text != "") && (txtPhoneNo.Text != null && txtPhoneNo.Text != "") && ((cbCompanyName.Text != null && cbCompanyName.Text != "") || (txtCompanyName.Text != null && txtCompanyName.Text != "")) && (txtDateSigned.Text != null && txtDateSigned.Text != "")) { #region important variables (customer, duplicateLead) var customer = new Customer(); var duplicateLead = context.Leads.FirstOrDefault (c => c.CompanyName.ToLower().Contains(txtCompanyName.Text.ToLower())); #endregion if (CustomerId > 0) { #region edit customer = context.Customers.FirstOrDefault(c => c.CustomerID == CustomerId); var duplicateName = context.Customers.FirstOrDefault (c => c.CompanyName.ToLower() == txtCompanyName.Text.ToLower() && c.CustomerID == customer.CustomerID); if (customer != null) { if ((duplicateName != null) && (duplicateLead == null)) { if (tsFromLeadCheck.IsChecked.Value != true) { customer.CompanyAddress = txtAddress.Text; customer.CompanyName = txtCompanyName.Text; customer.LeadID = 0; } else { var lead = context.Leads.FirstOrDefault(c => c.LeadID == customer.LeadID); customer.CompanyAddress = lead.CompanyAddress; customer.CompanyName = lead.CompanyName; customer.LeadID = lead.LeadID; } customer.Email = txtEmail.Text; customer.PhoneNo = txtPhoneNo.Text; if (txtWebsite.Text != null && txtWebsite.Text != "") { customer.Website = txtWebsite.Text; } else { customer.Website = ""; } customer.DateSigned = Convert.ToDateTime(txtDateSigned.Text).ToString("MM/dd/yyyy"); 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 + " modifies " + customer.CompanyName + "'s details."; context.Logs.Add(log); context.SaveChanges(); var window = new NoticeWindow(); NoticeWindow.message = "Customer details successfully updated"; window.Height = 0; window.Top = screenTopEdge + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.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 + " fails to modify " + customer.CompanyName + "'s details because an existing name is detected."; context.Logs.Add(log); context.SaveChanges(); var window = new NoticeWindow(); NoticeWindow.message = "A similar name already exists"; window.Height = 0; window.Top = screenTopEdge + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); } } #endregion } else { #region add if (duplicateLead == null) { if (tsFromLeadCheck.IsChecked.Value != false) { var lead = context.Leads.FirstOrDefault (c => c.CompanyName.ToLower() == cbCompanyName.Text.ToLower()); customer.CompanyAddress = lead.CompanyAddress; customer.CompanyName = lead.CompanyName; customer.LeadID = lead.LeadID; } else { customer.CompanyAddress = txtAddress.Text; customer.CompanyName = txtCompanyName.Text; customer.LeadID = 0; } customer.DateSigned = Convert.ToDateTime(txtDateSigned.Text).ToString("MM/dd/yyyy"); customer.Email = txtEmail.Text; customer.PhoneNo = txtPhoneNo.Text; if (txtWebsite.Text != null && txtWebsite.Text != "") { customer.Website = txtWebsite.Text; } else { customer.Website = ""; } context.Customers.Add(customer); 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 + " creates a new customer. (" + customer.CompanyName + ")"; context.Logs.Add(log); var window = new NoticeWindow(); NoticeWindow.message = "Customer successfully created"; window.Height = 0; window.Top = screenTopEdge + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); context.SaveChanges(); } 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 + " fails to create a new customer " + " because an existing name has been detected."; context.Logs.Add(log); context.SaveChanges(); var window = new NoticeWindow(); NoticeWindow.message = "The name already exists"; window.Height = 0; window.Top = screenTopEdge + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); } #endregion } } else { var window = new NoticeWindow(); NoticeWindow.message = "Please fill all boxes labeled with an asterisk(*) symbol."; window.Height = 0; window.Top = screenTopEdge + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); } } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { if (AgentId > 0) { lblAgentId.Visibility = Visibility.Visible; txtAgentId.Visibility = Visibility.Visible; Grid.SetRow(lblAgentName, 1); Grid.SetRow(gridAgentName, 1); Grid.SetColumn(gridAgentName, 1); Grid.SetRow(lblPosition, 2); Grid.SetRow(txtPosition, 2); Grid.SetColumn(txtPosition, 1); Grid.SetRow(lblContactNo, 3); Grid.SetRow(txtContactNo, 3); Grid.SetColumn(txtContactNo, 1); Grid.SetRow(lblTerritory, 4); Grid.SetRow(txtTerritory, 4); Grid.SetColumn(txtTerritory, 1); var agent = context.Agents.FirstOrDefault(c => c.AgentId == AgentId); if (agent != null) { txtAgentId.Text = Convert.ToString(agent.AgentId); txtAgentName.Text = agent.AgentName; txtPosition.Text = agent.Position; txtContactNo.Text = agent.ContactNo; txtTerritory.Text = agent.Territory; } } else { lblAgentId.Visibility = Visibility.Hidden; txtAgentId.Visibility = Visibility.Hidden; Grid.SetRow(lblAgentName, 0); Grid.SetRow(gridAgentName, 0); Grid.SetColumn(gridAgentName, 1); Grid.SetRow(lblPosition, 1); Grid.SetRow(txtPosition, 1); Grid.SetColumn(txtPosition, 1); Grid.SetRow(lblContactNo, 2); Grid.SetRow(txtContactNo, 2); Grid.SetColumn(txtContactNo, 1); Grid.SetRow(lblTerritory, 3); Grid.SetRow(txtTerritory, 3); Grid.SetColumn(txtTerritory, 1); } } if (isSelectFinish == true) { if (Variables.yesClicked == true) { using (var context = new DatabaseContext()) { string empname = EmployeeSelection.selectedEmployee; var emp = context.Employees.FirstOrDefault(c => c.FirstName + " " + c.MiddleName + " " + c.LastName == empname); var duplicate = context.Agents.Where (c => c.AgentName.ToLower() == emp.FirstName.ToLower() + " " + emp.MiddleName.ToLower() + " " + emp.LastName.ToLower()).ToList(); List<EmployeeView> employee = new List<EmployeeView>(); if (duplicate.Count() != 0) { var window2 = new NoticeWindow(); NoticeWindow.message = "Employee already has a user account."; double screenWidth2 = Application.Current.MainWindow.Width; window2.Height = 0; window2.Top = Application.Current.MainWindow.Top + 8; window2.Left = (screenWidth2 / 2) - (window2.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window2.Left += screenLeftEdge; } window2.ShowDialog(); isSelectFinish = false; } else { txtAgentName.Text = empname; txtPosition.Text = emp.Position; txtTerritory.Text = emp.Territory; txtAgentName.IsReadOnly = true; txtPosition.IsReadOnly = true; txtTerritory.IsReadOnly = true; isSelectFinish = false; } } } } }
private void NullMessage() { var windows = new 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 RefreshLogs() { var message = await QueryLogs(); if (message != null) { var windows = new 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(); } else { using (var context = new DatabaseContext()) { var textBlock = new TextBlock(); var logs = context.Logs.OrderByDescending(c => c.LogId).ToList(); Thickness margin = textBlock.Margin; var specificStackPanel = new StackPanel(); var wholeStackPanel = new StackPanel(); var separator = new Separator(); BrushConverter conveter = new BrushConverter(); Brush brush = conveter.ConvertFromString("#FF0069FF") as Brush; textBlock.TextWrapping = TextWrapping.Wrap; wholeStackPanel.Height = Double.NaN; specificStackPanel.Height = Double.NaN; sbLogs.Content = null; wholeStackPanel.Children.Clear(); foreach (var log in logs) { //textblock for date and time specificStackPanel = new StackPanel(); textBlock = new TextBlock(); textBlock.Text = Convert.ToDateTime(log.Date).ToString("MMMM d, yyyy") + " " + Convert.ToDateTime(log.Time).ToString("hh:mm:ss tt"); margin.Top = 5; margin.Bottom = 5; margin.Left = 10; margin.Right = 10; textBlock.Margin = margin; specificStackPanel.Children.Add(textBlock); //textblock for log description textBlock = new TextBlock(); textBlock.Text = log.Description; margin.Top = 0; margin.Bottom = 5; margin.Left = 10; margin.Right = 20; textBlock.Margin = margin; specificStackPanel.Children.Add(textBlock); separator = new Separator(); brush = conveter.ConvertFromString("#FF0069FF") as Brush; separator.BorderBrush = brush; specificStackPanel.Children.Add(separator); wholeStackPanel.Children.Add(specificStackPanel); } sbLogs.Content = wholeStackPanel; lblTotalLogs.Text = "Total : " + logs.Count(); } } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { var selectedUser = dcUsersList.SelectedItem as UsersLists; if (selectedUser != null) { var user = context.UserAccounts.FirstOrDefault (c => c.UserAccountId.ToLower() == selectedUser.UserAccountId.ToLower()); if (user != null) { var window = new MessageBoxWindow("Are you sure you want to permanently 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.UserAccounts.Remove(user); var windows = new NoticeWindow(); NoticeWindow.message = "Lead succesfully 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(); } } LoadUsers(); } }
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 UserControl_Loaded(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { var lead = new Lead(); var territory = new Territory(); var salesStage = context.SalesStages.OrderBy(c => c.RankNo).Select(c => c.SalesStageName).ToList(); var territories = context.Territories.Select(c => c.TerritoryName).ToList(); var marketingStrategies = context.MarketingStrategies.Select(c => c.Description).ToList(); cbTerritory.ItemsSource = null; if (territories != null) { cbTerritory.ItemsSource = territories; } else { var windows = new NoticeWindow(); NoticeWindow.message = "No territories"; windows.Height = 0; windows.Top = screenTopEdge + 8; windows.Left = (screenWidth / 2) - (windows.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; } windows.ShowDialog(); } cbStatus.ItemsSource = null; if (salesStage != null) { cbStatus.ItemsSource = salesStage; } else { var windows = new NoticeWindow(); NoticeWindow.message = "No sales stage statuses"; windows.Height = 0; windows.Top = screenTopEdge + 8; windows.Left = (screenWidth / 2) - (windows.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; } windows.ShowDialog(); } cbMarketingStrategy.ItemsSource = null; if (marketingStrategies != null) { cbMarketingStrategy.ItemsSource = marketingStrategies; } else { var windows = new NoticeWindow(); NoticeWindow.message = "No marketing strategies"; 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 (LeadId > 0) { lead = context.Leads.FirstOrDefault(c => c.LeadID == LeadId); territory = context.Territories.FirstOrDefault(c => c.TerritoryID == lead.TerritoryID); var marketingStrategy = context.MarketingStrategies.FirstOrDefault(c => c.MarketingStrategyId == lead.MarketingStrategyId); var leadsProducts = context.LeadsProducts.Where(c => c.LeadId == lead.LeadID).ToList(); ; if (lead != null) { lblLeadId.Visibility = Visibility.Visible; txtLeadId.Visibility = Visibility.Visible; Grid.SetRow(lblCompanyName, 1); Grid.SetRow(txtCompanyName, 1); Grid.SetColumn(txtCompanyName, 1); Grid.SetRow(lblAddress, 2); Grid.SetRow(txtCompanyAddress, 2); Grid.SetColumn(txtCompanyAddress, 1); Grid.SetRow(lblTerritory, 3); Grid.SetRow(cbTerritory, 3); Grid.SetColumn(cbTerritory, 1); Grid.SetRow(lblSalesStageStatus, 4); Grid.SetRow(cbStatus, 4); Grid.SetColumn(cbStatus, 1); Grid.SetRow(lblMarketingStrategy, 5); Grid.SetRow(cbMarketingStrategy, 5); Grid.SetColumn(cbMarketingStrategy, 1); Grid.SetRow(lblProduct, 6); Grid.SetRow(gridProduct, 6); Grid.SetColumn(gridProduct, 1); Grid.SetRow(lblActiveCheck, 7); Grid.SetRow(tsActiveCheck, 7); Grid.SetColumn(tsActiveCheck, 1); txtLeadId.Text = Convert.ToString(lead.LeadID); txtCompanyAddress.Text = lead.CompanyAddress; txtCompanyName.Text = lead.CompanyName; cbTerritory.SelectedItem = territory.TerritoryName; cbStatus.SelectedItem = lead.Status; tsActiveCheck.IsChecked = lead.IsActive; if (marketingStrategy != null) { cbMarketingStrategy.SelectedItem = marketingStrategy.Description; } else { cbMarketingStrategy.SelectedItem = null; } if (leadsProducts != null) { foreach (var leadsProduct in leadsProducts) { lbLeadsProducts.Items.Add(leadsProduct); } } else { lbLeadsProducts.Items.Clear(); } } } else { lblLeadId.Visibility = Visibility.Hidden; txtLeadId.Visibility = Visibility.Hidden; Grid.SetRow(lblCompanyName, 0); Grid.SetRow(txtCompanyName, 0); Grid.SetColumn(txtCompanyName, 1); Grid.SetRow(lblAddress, 1); Grid.SetRow(txtCompanyAddress, 1); Grid.SetColumn(txtCompanyAddress, 1); Grid.SetRow(lblTerritory, 2); Grid.SetRow(cbTerritory, 2); Grid.SetColumn(cbTerritory, 1); Grid.SetRow(lblSalesStageStatus, 3); Grid.SetRow(cbStatus, 3); Grid.SetColumn(cbStatus, 1); Grid.SetRow(lblMarketingStrategy, 4); Grid.SetRow(cbMarketingStrategy, 4); Grid.SetColumn(cbMarketingStrategy, 1); Grid.SetRow(lblProduct, 5); Grid.SetRow(gridProduct, 5); Grid.SetColumn(gridProduct, 1); Grid.SetRow(lblActiveCheck, 6); Grid.SetRow(tsActiveCheck, 6); Grid.SetColumn(tsActiveCheck, 1); txtCompanyAddress.Text = ""; txtCompanyName.Text = ""; cbStatus.SelectedItem = null; cbTerritory.SelectedItem = null; tsActiveCheck.IsChecked = true; cbMarketingStrategy.SelectedItem = null; if (isSelectFinish != true) { lbLeadsProducts.Items.Clear(); } } } #region selection finish if (isSelectFinish != false) { if (Variables.yesClicked == true) { using (var context = new DatabaseContext()) { var product = ProductSelection.passList; lbLeadsProducts.Items.Add(product); isSelectFinish = false; Variables.yesClicked = false; } } } #endregion }
private void dcProductsList_SelectedItemChanged(object sender, DevExpress.Xpf.Grid.SelectedItemChangedEventArgs e) { using (var context = new DatabaseContext()) { try { var selectedProduct = dcProductsList.SelectedItem as ProductView; var leads = context.Leads.ToList(); lblLeads.Text = selectedProduct.ProductName; leadsList.Clear(); if (selectedProduct != null && leads != null) { foreach (var lead in leads) { var territory = context.Territories.FirstOrDefault(c => c.TerritoryID == lead.TerritoryID); var strategy = context.MarketingStrategies.FirstOrDefault(c => c.MarketingStrategyId == lead.MarketingStrategyId); if (territory != null && strategy != null) { leadsList.Add(new LeadsView { LeadId = lead.LeadID, CompanyAddress = lead.CompanyAddress, CompanyName = lead.CompanyName, SalesStageStatus = lead.Status, TerritoryName = territory.TerritoryName, DateAdded = lead.DateAdded, IsActive = lead.IsActive, MarketingStrategy = strategy.Description }); } else { leadsList.Add(new LeadsView { LeadId = lead.LeadID, CompanyAddress = lead.CompanyAddress, CompanyName = lead.CompanyName, SalesStageStatus = lead.Status, TerritoryName = territory.TerritoryName, DateAdded = lead.DateAdded, IsActive = lead.IsActive, MarketingStrategy = strategy.Description }); } } } dcLeadsList.ItemsSource = leadsList.ToList(); viewLead.BestFitColumns(); } catch (Exception ex) { var windows = new NoticeWindow(); NoticeWindow.message = "Error : " + ex.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(); } } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { int productNo = 0; if (productsList.Count() > 0) { List<ProductsReportData> dataList = new List<ProductsReportData>(); List<ProductsReportDetails> detailsList = new List<ProductsReportDetails>(); List<LeadsPerProducts> leadsList = new List<LeadsPerProducts>(); var leads = context.Leads.ToList(); foreach (var product in productsList) { if (product != null) { productNo++; var detail = new ProductsReportDetails(); detail.Category = product.Category; detail.Cost = product.Cost; detail.ProductId = productNo; detail.ProductName = product.ProductName; detailsList.Add(detail); } if (leads != null) { foreach (var lead in leads) { var toReport = new LeadsPerProducts(); toReport.LeadName = lead.CompanyName; leadsList.Add(toReport); } } } dataList.Add(new ProductsReportData() { ReportHeader = "PRODUCTS", ReportTitle = "PRODUCTS OF as of " + DateTime.Now.ToString("MMMM dd, yyyy"), TotalProducts = detailsList.Count(), details = detailsList, leads = leadsList }); var report = new ProductsReportDesign { DataSource = dataList.Distinct(), Name = "LEAD ACTIVITIES OF as of " + DateTime.Now.ToString("MMMM dd, yyyy") }; using (ReportPrintTool printTool = new ReportPrintTool(report)) { printTool.ShowRibbonPreviewDialog(); } } else { var windows = new NoticeWindow(); 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 async void RefreshProductTables(string str) { try { string message = ""; busyIndicator.IsBusy = true; message = await QueryLoadProducts(); if (message != null) { var windows = new 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 (productsList.Count() > 0) { dcProductsList.ItemsSource = productsList.Where (c => c.ProductName.ToLower().Contains(str.ToLower()) && (c.ProductName != "" && c.ProductName != null)). OrderBy(c => c.ProductID).ToList(); viewProducts.BestFitColumns(); } else { var windows = new NoticeWindow(); NoticeWindow.message = "List has no products."; 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; } catch (Exception ex) { var windows = new NoticeWindow(); NoticeWindow.message = "Error : " + ex.InnerException; 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 RefreshLeadTables(string str) { try { string message = ""; busyIndicator.IsBusy = true; message = await QueryLoadLeads(); if (message != null) { var windows = new 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 (leadsList.Count() > 0) { using (var context = new DatabaseContext()) { var selectedProduct = dcProductsList.SelectedItem as ProductView; var product = context.Products.FirstOrDefault(c => c.ProductID == selectedProduct.ProductID); dcLeadsList.ItemsSource = leadsList.Where (c => c.CompanyName.ToLower().Contains(str.ToLower())). OrderBy(c => c.LeadId).ToList(); viewLead.BestFitColumns(); } } else { var windows = new NoticeWindow(); NoticeWindow.message = "List has no leads."; 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; } catch (Exception ex) { var windows = new NoticeWindow(); NoticeWindow.message = "Error : " + ex.InnerException; 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 btnOK_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { if (listProducts.SelectedItems != null) { foreach (var product in listProducts.SelectedItems) { var convertedProduct = Convert.ToString(product); var prod = context.Products.FirstOrDefault(c => c.ProductName == convertedProduct); passList = prod.ProductName; } Variables.yesClicked = true; var frame = DevExpress.Xpf.Core.Native.LayoutHelper.FindParentObject<NavigationFrame>(this); frame.BackNavigationMode = BackNavigationMode.PreviousScreen; frame.GoBack(); LeadForm.isSelectFinish = true; } else { var window = new NoticeWindow(); NoticeWindow.message = "Please select a row."; window.Height = 0; window.Top = Application.Current.MainWindow.Top + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); } } }
private void btnSave_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { if (((txtProductCategory.Text != null || txtProductCategory.Text != "") || (cbProductCategory.SelectedItem != null)) && (txtProductName.Text != null || txtProductName.Text != "")) { if (ProductId > 0) { var product = context.Products.FirstOrDefault(c => c.ProductID == ProductId); #region edit if (product != null) { var duplicateProduct = context.Products.FirstOrDefault (c => c.ProductID == product.ProductID && c.ProductName.ToLower().Contains(txtProductName.Text.ToLower())); var existingProduct = context.Products.FirstOrDefault (c => c.ProductName.ToLower().Contains(txtProductName.Text.ToLower())); if (duplicateProduct != null || existingProduct == null) { product.CategoryID = Convert.ToInt32(txtProductId.Text); product.ProductName = txtProductName.Text; if (txtCost.Text != null || txtCost.Text != "") { product.Cost = Convert.ToDouble(txtCost.Text); } else { product.Cost = 0.00; } if (txtProductCategory.Visibility == Visibility.Visible) { var category = context.ProductCategories.FirstOrDefault (c => c.CategoryName.ToLower() == txtProductCategory.Text.ToLower()); if (category != null) { product.CategoryID = category.CategoryID; } } else if (cbProductCategory.Visibility == Visibility.Visible) { var category = context.ProductCategories.FirstOrDefault (c => c.CategoryName.ToLower() == cbProductCategory.Text.ToLower()); if (category != null) { product.CategoryID = category.CategoryID; } } 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 + " modifies " + txtProductName.Text + "'s details."; context.Logs.Add(log); var window = new NoticeWindow(); NoticeWindow.message = "Product successfully modified"; window.Height = 0; window.Top = screenTopEdge + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); context.SaveChanges(); } 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 + " tries to modify " + product.ProductName + "'s details but fails due to a similar name as the product already exists."; context.Logs.Add(log); context.SaveChanges(); var windows = new NoticeWindow(); NoticeWindow.message = "Similar product name 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(); } } #endregion } else { #region add var product = context.Products.FirstOrDefault (c => c.ProductName.ToLower().Contains(txtProductName.Text.ToLower())); var category = context.ProductCategories.FirstOrDefault (c => c.CategoryName.ToLower() == cbProductCategory.Text.ToLower()); if ((product == null) && (category != null)) { product = new Product(); product.CategoryID = category.CategoryID; if ((txtCost.Text != null) && (txtCost.Text != "")) { product.Cost = Convert.ToDouble(txtCost.Text); } else { product.Cost = 0.00; } product.ProductName = txtProductName.Text; context.Products.Add(product); 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 + " creates a new customer. (" + product.ProductName + ")"; context.Logs.Add(log); var window = new NoticeWindow(); NoticeWindow.message = "Product successfully created"; window.Height = 0; window.Top = screenTopEdge + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); context.SaveChanges(); } 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 + " tries to create a new"+ " customer but fails due to the product already exists."; context.Logs.Add(log); var window = new NoticeWindow(); NoticeWindow.message = "Product already exists"; window.Height = 0; window.Top = screenTopEdge + 8; window.Left = (screenWidth / 2) - (window.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { window.Left += screenLeftEdge; } window.ShowDialog(); context.SaveChanges(); } #endregion } } else { var windows = new NoticeWindow(); NoticeWindow.message = "Please fill all the 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 async void RefreshTable(string str) { using (var context = new DatabaseContext()) { string message = ""; busyIndicator.IsBusy = true; message = await QueryLoadAgents(); if (message != null) { var windows = new 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 (agentsList.Count() > 0) { dcAgentsList.ItemsSource = agentsList.Where (c => c.AgentName.ToLower().Contains(str.ToLower()) || c.ContactNo.ToLower().Contains(str.ToLower()) || c.Position.ToLower().Contains(str.ToLower()) || c.Territory.ToLower().Contains(str.ToLower())).ToList(); } else { dcAgentsList.ItemsSource = null; var windows = new Shared.Windows.NoticeWindow(); NoticeWindow.message = "List has no agents."; windows.Height = 0; windows.Top = screenTopEdge + 8; windows.Left = (screenWidth / 2) - (windows.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; } windows.ShowDialog(); } viewAgents.BestFitColumns(); busyIndicator.IsBusy = false; } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { if (isView != true) { if (ProductId > 0) { var product = context.Products.FirstOrDefault(c => c.ProductID == ProductId); if (product != null) { var category = context.ProductCategories.FirstOrDefault(c => c.CategoryID == product.CategoryID); if (category != null) { lblProductId.Visibility = Visibility.Visible; txtProductId.Visibility = Visibility.Visible; btnSave.Visibility = Visibility.Visible; if (cbProductCategory.Visibility == Visibility.Hidden) { cbProductCategory.Visibility = Visibility.Visible; } if (txtProductCategory.Visibility == Visibility.Visible) { txtProductCategory.Visibility = Visibility.Hidden; } if (txtProductName.IsReadOnly == true && txtCost.IsReadOnly == true) { txtProductName.IsReadOnly = false; txtCost.IsReadOnly = false; } Grid.SetRow(lblProductName, 1); Grid.SetRow(txtProductName, 1); Grid.SetColumn(txtProductName, 1); Grid.SetRow(lblProductCategory, 2); Grid.SetRow(cbProductCategory, 2); Grid.SetColumn(cbProductCategory, 1); Grid.SetRow(lblCost, 3); Grid.SetRow(txtCost, 3); Grid.SetColumn(txtCost, 1); txtProductId.Text = Convert.ToString(product.ProductID); txtProductName.Text = product.ProductName; txtCost.Text = Convert.ToString(product.Cost); cbProductCategory.SelectedItem = category.CategoryName; } } } else { lblProductId.Visibility = Visibility.Hidden; txtProductId.Visibility = Visibility.Hidden; btnSave.Visibility = Visibility.Visible; if (cbProductCategory.Visibility == Visibility.Hidden) { cbProductCategory.Visibility = Visibility.Visible; } if (txtProductCategory.Visibility == Visibility.Visible) { txtProductCategory.Visibility = Visibility.Hidden; } if (txtProductName.IsReadOnly == true && txtCost.IsReadOnly == true) { txtProductName.IsReadOnly = false; txtCost.IsReadOnly = false; } Grid.SetRow(lblProductName, 0); Grid.SetRow(txtProductName, 0); Grid.SetColumn(txtProductName, 1); Grid.SetRow(lblProductCategory, 1); Grid.SetRow(cbProductCategory, 1); Grid.SetColumn(cbProductCategory, 1); Grid.SetRow(lblCost, 2); Grid.SetRow(txtCost, 2); Grid.SetColumn(txtCost, 1); txtProductName.Text = ""; txtCost.Text = ""; cbProductCategory.SelectedItem = null; } } else { var product = context.Products.FirstOrDefault(c => c.ProductID == ProductId); if (product != null) { var category = context.ProductCategories.FirstOrDefault(c => c.CategoryID == product.CategoryID); if (category != null) { lblProductId.Visibility = Visibility.Visible; txtProductId.Visibility = Visibility.Visible; btnSave.Visibility = Visibility.Hidden; if (cbProductCategory.Visibility == Visibility.Visible) { cbProductCategory.Visibility = Visibility.Hidden; } if (txtProductCategory.Visibility == Visibility.Hidden) { txtProductCategory.Visibility = Visibility.Visible; } if (txtProductName.IsReadOnly != true && txtCost.IsReadOnly != true) { txtProductName.IsReadOnly = true; txtCost.IsReadOnly = true; } Grid.SetRow(lblProductName, 1); Grid.SetRow(txtProductName, 1); Grid.SetColumn(txtProductName, 1); Grid.SetRow(lblProductCategory, 2); Grid.SetRow(txtProductCategory, 2); Grid.SetColumn(txtProductCategory, 1); Grid.SetRow(lblCost, 3); Grid.SetRow(txtCost, 3); Grid.SetColumn(txtCost, 1); txtProductId.Text = Convert.ToString(product.ProductID); txtProductName.Text = product.ProductName; txtCost.Text = Convert.ToString(product.Cost); txtProductCategory.Text = category.CategoryName; } } } #region product category list var productCategory = context.ProductCategories.ToList(); cbProductCategory.ItemsSource = null; if (productCategory.Count() > 0) { cbProductCategory.ItemsSource = productCategory.OrderBy(c => c.CategoryName). Select(c => c.CategoryName).ToList(); } else { var windows = new NoticeWindow(); NoticeWindow.message = "Category list is unavailable."; 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 } }
private async void RefreshTables(string str) { string message = ""; busyIndicator.IsBusy = true; message = await QueryLoadLeads(); if (message != null) { var windows = new 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 (leadsList.Count() > 0) { dcLeadsList.ItemsSource = leadsList.Where(c => c.CompanyAddress.ToLower().Contains(txtSearch.Text.ToLower()) || c.CompanyName.ToLower().Contains(txtSearch.Text.ToLower()) || c.SalesStageStatus.ToLower().Contains(txtSearch.Text.ToLower()) || c.TerritoryName.ToLower().Contains(txtSearch.Text.ToLower())).OrderBy(c => c.LeadId).ToList(); viewLead.BestFitColumns(); viewContact.BestFitColumns(); } else { var windows = new NoticeWindow(); NoticeWindow.message = "List has no leads."; 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 btnPrintLead_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { int itemNo = 0; if (leadsList.Count() > 0) { List<LeadsReportData> dataList = new List<LeadsReportData>(); List<LeadsReportDetail> detailsList = new List<LeadsReportDetail>(); foreach (var lead in leadsList) { itemNo++; var detail = new LeadsReportDetail(); detail.Address = lead.CompanyAddress; detail.CompanyName = lead.CompanyName; detail.LeadNo = itemNo; detail.SalesStageStatus = lead.SalesStageStatus; detail.Territory = lead.TerritoryName; detailsList.Add(detail); } dataList.Add(new LeadsReportData() { ReportHeader = "LEADS", ReportTitle = "LEADS as of " + DateTime.Now.ToString("MMMM dd, yyyy"), TotalLeads = detailsList.Count(), details = detailsList }); var report = new LeadsReportDesign { DataSource = dataList.Distinct(), Name = "LEADS as of " + DateTime.Now.ToString("MMMM dd, yyyy") }; using (ReportPrintTool printTool = new ReportPrintTool(report)) { printTool.ShowRibbonPreviewDialog(); } } else { var windows = new NoticeWindow(); 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 selectedAgents = dcAgentsList.SelectedItem as AgentsView; if (selectedAgents != null) { var agent = context.Agents.FirstOrDefault(c => c.AgentId == selectedAgents.AgentId); if (agent != null) { var window = new MessageBoxWindow("Are you sure you want to permanently 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(); var account = context.CustomerAccounts.FirstOrDefault(c => c.AgentId == agent.AgentId); if (account == null) { if (Variables.yesClicked == true) { 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 Agent " + agent.AgentName + "."; context.Logs.Add(log); context.Agents.Remove(agent); var windows = new NoticeWindow(); NoticeWindow.message = "Agent 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(); } } LoadAgents(); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { if ((txtAgentName.Text != null || txtAgentName.Text != "") && (txtContactNo.Text != null || txtContactNo.Text != "") && (txtPosition.Text != null || txtPosition.Text != "") && (txtTerritory.Text != null || txtTerritory.Text != "")) { var agent = context.Agents.FirstOrDefault(c => c.AgentId == AgentId); if (AgentId > 0) { #region edit if (agent != null) { var checkExistingAgent = context.Agents.FirstOrDefault (c => c.AgentId == agent.AgentId && c.AgentName.ToLower().Contains(txtAgentName.Text.ToLower())); var duplicateAgent = context.Agents.FirstOrDefault (c => c.AgentName.ToLower().Contains(txtAgentName.Text.ToLower())); if ((checkExistingAgent != null) || (duplicateAgent == null)) { agent.AgentName = txtAgentName.Text; agent.ContactNo = txtContactNo.Text; agent.Position = txtPosition.Text; agent.Territory = txtTerritory.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 + " modifies Agent " + agent.AgentName + "'s details."; context.Logs.Add(log); var windows = new NoticeWindow(); NoticeWindow.message = "Agent successfully modified"; 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(); //AgentsMasterData.isFinish = true; } 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 + " fails to modify " + agent.AgentName + "'s details because an agent with a similar name is detected."; context.Logs.Add(log); context.SaveChanges(); var windows = new NoticeWindow(); NoticeWindow.message = "Similar agent name 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(); } } #endregion } else { #region add var checkExistingAgent = context.Agents.FirstOrDefault (c => c.AgentName.ToLower().Contains(txtAgentName.Text.ToLower())); if (checkExistingAgent == null) { agent = new Agent(); agent.AgentName = txtAgentName.Text; agent.ContactNo = txtContactNo.Text; agent.Position = txtPosition.Text; agent.Territory = txtTerritory.Text; if (txtAgentName.IsReadOnly == true && txtPosition.IsReadOnly == true && txtTerritory.IsReadOnly == true) { agent.IsEmployee = true; } else { agent.IsEmployee = false; } context.Agents.Add(agent); 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 + " creates a new agent. (" + agent.AgentName + ")"; context.Logs.Add(log); var windows = new NoticeWindow(); NoticeWindow.message = "Agent 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(); context.SaveChanges(); //AgentsMasterData.isFinish = true; } 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 + " fails to create a new agent" + " because the agent already exists."; context.Logs.Add(log); context.SaveChanges(); var windows = new NoticeWindow(); NoticeWindow.message = "Agent 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 fill all boxes labeled with an asterisk(*) symbol."; 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 btnDeleteContact_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { var selectedContact = dcContactsList.SelectedItem as ContactView; if (selectedContact != null) { var contact = context.Contacts.FirstOrDefault(c => c.ContactID == selectedContact.ContactId); if (contact != null) { var window = new MessageBoxWindow("Are you sure you want to delete this contact person?"); 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 activity = context.LeadActivities.Where(c => ((c.ActivityDate == null || c.ActivityDate == "") || (c.ActivityTime == null || c.ActivityTime == "")) && (c.IsFinalized == false)).FirstOrDefault(c => c.LeadID == contact.LeadId); if (activity != null) { var windows = new NoticeWindow(); NoticeWindow.message = "Contact person still has an unaccomplished activity."; 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 = contact.ContactPersonName + " is not deleted due to unaccomplished activity(ies)."; log.Time = DateTime.Now.ToString("hh:mm:ss tt"); context.Logs.Add(log); context.SaveChanges(); } else { busyIndicator.IsBusy = true; context.Contacts.Remove(contact); var lead = context.Leads.FirstOrDefault(c => c.LeadID == contact.LeadId); var log = new Log(); log.Date = DateTime.Now.ToString("MM/dd/yyyy"); log.Description = NotificationWindow.username + " deleted " + contact.ContactPersonName + " from " + lead.CompanyName + " contacts."; log.Time = DateTime.Now.ToString("hh:mm:ss tt"); context.Logs.Add(log); var windows = new NoticeWindow(); NoticeWindow.message = "Contact person 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 { busyIndicator.IsBusy = true; NullMessage(); } LoadLeads(); busyIndicator.IsBusy = false; } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { using (var context= new DatabaseContext()) { var selectedSalestage = dcSalesStagesList.SelectedItem as SalesStagesView; if (selectedSalestage != null) { var salestage = context.SalesStages.First(c => c.SalesStageID == selectedSalestage.SalesStageID); if (salestage != 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.SalesStages.Remove(salestage); var log = new Log(); log.Date = DateTime.Now.ToString("MM/dd/yyyy"); log.Description = NotificationWindow.username + " deleted " + salestage.SalesStageName + " sales stage status."; log.Time = DateTime.Now.ToString("hh:mm:ss tt"); context.Logs.Add(log); var windows = new NoticeWindow(); NoticeWindow.message = "Sales stage 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(); } } LoadActivity(); } }
private void btnPrintContact_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { int itemNo = 0; if (contactsList.Count() > 0) { List<ContactsReportData> dataList = new List<ContactsReportData>(); List<ContactsReportDetail> detailsList = new List<ContactsReportDetail>(); foreach (var contact in contactsList) { itemNo++; var detail = new ContactsReportDetail(); detail.CompanyName = contact.Company; detail.ContactNo = itemNo; detail.ContactPerson = contact.ContactPersonName; detail.PhoneNo = contact.PhoneNo; detail.Position = contact.Position; detailsList.Add(detail); } dataList.Add(new ContactsReportData() { ReportHeader = "CONTACT PERSONS", ReportTitle = "CONTACT PERSONS as of " + DateTime.Now.ToString("MMMM dd, yyyy"), TotalContacts = detailsList.Count(), details = detailsList }); var report = new ContactsReportDesign { DataSource = dataList.Distinct(), Name = "CONTACT PERSONS as of " + DateTime.Now.ToString("MMMM dd, yyyy") }; using (ReportPrintTool printTool = new ReportPrintTool(report)) { printTool.ShowRibbonPreviewDialog(); } } else { var windows = new NoticeWindow(); NoticeWindow.message = "No details 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 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(); } } }
private async void RefreshTables(string str) { FillCharts(); if (isEntered != true) { AddLogAccess(); } using (var context = new DatabaseContext()) { string message = ""; busyIndicator.IsBusy = true; message = await QueryLoadLeadDashboard(); if (message != null) { var windows = new 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 (leadListBox.Count() > 0) { lbeLeads.ItemsSource = leadListBox.Select(c => c.CompanyName).ToList(); } else { lbeLeads.ItemsSource = null; var windows = new NoticeWindow(); NoticeWindow.message = "No leads in the list."; windows.Height = 0; windows.Top = screenTopEdge + 8; windows.Left = (screenWidth / 2) - (windows.Width / 2); if (screenLeftEdge > 0 || screenLeftEdge < -8) { windows.Left += screenLeftEdge; } windows.ShowDialog(); } lblTotalLead.Text = "Total Leads : " + leadListBox.Count(); busyIndicator.IsBusy = false; } }
private void btnSave_Click(object sender, RoutedEventArgs e) { using (var context = new DatabaseContext()) { if (ActivityId > 0) { var activity = context.LeadActivities.FirstOrDefault(c => c.ActivityID == ActivityId); var selectedContact = Convert.ToString(cbContact.SelectedItem); if (activity != null) { var contact = context.Contacts.FirstOrDefault(c => c.ContactPersonName.ToLower() == selectedContact.ToLower()); if (txtActivityDate.Text != null && txtActivityTime.Text != null && txtCost.Text != null && txtNextStepDue.Text != null && txtMarketingVoucher.Text != null && txtNextStep.Text != null && txtSalesRep.Text != null && cbContact.Text != null) { var windows = new NoticeWindow(); if (Convert.ToDateTime(txtActivityDate.Text).Date >= DateTime.Now.Date && Convert.ToDateTime(txtNextStepDue.Text).Date >= Convert.ToDateTime(txtActivityDate.Text).Date) { activity.ActivityDate = Convert.ToDateTime(txtActivityDate.Text).ToString("MM/dd/yyyy"); activity.ActivityID = Convert.ToInt32(txtActivityId.Text); activity.ActivityTime = Convert.ToDateTime(txtActivityTime.Text).ToString("HH:mm"); if (txtClientResponse.Text != null) { activity.ClientResponse = txtClientResponse.Text; } activity.Cost = Convert.ToDouble(txtCost.Text); if (txtDescription.Text != null) { activity.Description = txtDescription.Text; } if (txtTransactionDetails.Text != null) { activity.DetailsOfTransaction = txtTransactionDetails.Text; } activity.DueDateOfNextStep = Convert.ToDateTime(txtNextStepDue.Text).ToShortDateString(); activity.LeadID = LeadId; activity.MarketingVoucherNo = txtMarketingVoucher.Text; activity.NextStep = txtNextStep.Text; activity.SalesRep = txtSalesRep.Text; activity.ContacId = contact.ContactID; activity.IsFinalized = tsFinalizedCheck.IsChecked.Value; var lead = context.Leads.FirstOrDefault(c => c.LeadID == LeadId); var log = new Log(); log.Date = DateTime.Now.ToString("MM/dd/yyyy"); log.Description = NotificationWindow.username + " modified " + lead.CompanyName + "'s activity."; log.Time = DateTime.Now.ToString("hh:mm:ss tt"); context.Logs.Add(log); context.SaveChanges(); 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(); } else if (Convert.ToDateTime(txtNextStepDue.Text).Date < Convert.ToDateTime(txtActivityDate.Text).Date) { NoticeWindow.message = "Due date of next step must be after the date of the activity date."; 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 { NoticeWindow.message = "Activity date must not be before today."; 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 that is 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(); } } } else { var selectedContact = Convert.ToString(cbContact.SelectedItem); var activity = new LeadActivity(); var contact = context.Contacts.FirstOrDefault(c => c.ContactPersonName.ToLower() == selectedContact.ToLower()); if (txtCost.Text != null && txtSalesRep.Text != null && cbContact.SelectedItem != null) { activity.Cost = Convert.ToDouble(txtCost.Text); if (txtDescription.Text != null) { activity.Description = txtDescription.Text; } activity.LeadID = LeadId; if (txtMarketingVoucher.Text != null) { activity.MarketingVoucherNo = txtMarketingVoucher.Text; } activity.SalesRep = txtSalesRep.Text; activity.ContacId = contact.ContactID; activity.IsFinalized = false; context.LeadActivities.Add(activity); var lead = context.Leads.FirstOrDefault(c => c.LeadID == LeadId); var log = new Log(); log.Date = DateTime.Now.ToString("MM/dd/yyyy"); log.Description = NotificationWindow.username + " created an activity for " + lead.CompanyName + "."; log.Time = DateTime.Now.ToString("hh:mm:ss tt"); context.Logs.Add(log); context.SaveChanges(); var windows = new NoticeWindow(); NoticeWindow.message = "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 windows = new NoticeWindow(); NoticeWindow.message = "Please provide all that is 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(); } } } }