private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (e.RowIndex >= 0)
            {
                var selectedItem = senderGrid.Rows[e.RowIndex].DataBoundItem as MyReminders;
                if (selectedItem != null)
                {
                    using (var context = SqlDataHandler.GetDataContext())
                    {
                        var obj = context.tblReminders.Where(a => a.id == selectedItem.RemID).FirstOrDefault();

                        obj.action = selectedItem.Action;
                        if (selectedItem.Action)
                        {
                            obj.actionDate = DateTime.Now;
                        }
                        else
                        {
                            obj.actionDate = null;
                        }
                        context.SaveChanges();
                    }

                    UpdateRowColours();
                }
            }
        }
        private void dgMonthly_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                var selectedItem = senderGrid.Rows[e.RowIndex].DataBoundItem as MonthReport;
                if (selectedItem != null)
                {
                    using (var context = SqlDataHandler.GetDataContext())
                    {
                        var curr = context.tblMonthFins.Where(a => a.id == selectedItem.Id).SingleOrDefault();
                        if (curr != null)
                        {
                            curr.AdditionalComments = selectedItem.AdditionalComments;

                            //future
                            var future = context.tblMonthFins.Where(a => a.buildingID == curr.buildingID && a.findate > curr.findate).ToList();
                            foreach (var item in future)
                            {
                                item.AdditionalComments = selectedItem.AdditionalComments;
                            }

                            context.SaveChanges();
                            Controller.ShowMessage("Comment updated");
                        }
                    }
                }
            }
        }
Example #3
0
 private void LoadBanks()
 {
     using (var context = SqlDataHandler.GetDataContext())
     {
         _BankList = context.BankSet.OrderBy(a => a.Name).ToList();
     }
 }
 private void RollbackRequsitionBatch(RequisitionBatch batch)
 {
     using (var context = SqlDataHandler.GetDataContext())
     {
         context.RequisitionBatchRollback(batch.id);
     }
 }
        private void LoadReminders()
        {
            bsRem.Clear();

            using (var context = SqlDataHandler.GetDataContext())
            {
                var start = DateTime.Today.AddDays(-30);

                var q = from r in context.tblReminders
                        where r.UserId == Controller.user.id &&
                        (r.action == false || r.actionDate == null || r.actionDate > start)
                        select new MyReminders()
                {
                    RemID        = r.id,
                    Building     = r.Building.Building,
                    Customer     = r.customer,
                    ReminderDate = r.remDate,
                    Reminder     = r.remNote,
                    Contacts     = r.Contacts,
                    Phone        = r.Phone,
                    Fax          = r.Fax,
                    Email        = r.Email,
                    Action       = r.action
                };

                bsRem.DataSource = q.OrderBy(a => a.Action).ThenBy(a => a.ReminderDate).ToList();
            }
        }
        private void DisplayManagementPack(ManagementPackPreviewItem item)
        {
            _SelectedItem = item;
            Cursor        = Cursors.WaitCursor;
            try
            {
                Application.DoEvents();

                using (var context = SqlDataHandler.GetDataContext())
                {
                    var dataItem = context.ManagementPackSet.Single(a => a.id == _SelectedItem.Id);
                    tbComments.Text = dataItem.Commments;

                    string tempPDFFile = "";

                    tempPDFFile = Path.GetTempPath();
                    if (!tempPDFFile.EndsWith(@"\"))
                    {
                        tempPDFFile = tempPDFFile + @"\";
                    }

                    tempPDFFile = tempPDFFile + System.Guid.NewGuid().ToString("N") + ".pdf";
                    _SelectedItem.PDFFileName = tempPDFFile;
                    File.WriteAllBytes(_SelectedItem.PDFFileName, dataItem.ReportData);

                    DisplayPDF();
                }
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (_SelectedItem == null || String.IsNullOrWhiteSpace(_SelectedItem.PDFFileName))
            {
                Controller.HandleError("Please select an item from the list.", "Validation Error");
                return;
            }

            if (!Controller.AskQuestion("Are you sure you want to set the selected items as published notifying trustrees and without uploading to the website?"))
            {
                return;
            }

            using (var context = SqlDataHandler.GetDataContext())
            {
                var dataItem = context.ManagementPackSet.Single(a => a.id == _SelectedItem.Id);
                _SelectedItem.Processed = true;
                dataItem.Published      = true;
                dataItem.Commments      = tbComments.Text;
                context.SaveChanges();
                BindDataGrid();
                ClosePDF();
                Application.DoEvents();
            }
        }
 private void CommitRequisitionBatch(RequisitionBatch batch)
 {
     using (var context = SqlDataHandler.GetDataContext())
     {
         context.CommitRequisitionBatch(batch.id);
         SendPaymentNotifications(context, batch.id, Controller.user.email);
     }
 }
        private void LoadExistingPack()
        {
            var building = cmbBuilding.SelectedItem as Building;
            var year     = cmbYear.SelectedItem as IdValue;
            var month    = cmbMonth.SelectedItem as IdValue;

            var      dt  = new DateTime(year.Id, month.Id, 1);
            DateTime now = DateTime.Now;

            using (var context = SqlDataHandler.GetDataContext())
            {
                var managementPackReport = context.ManagementPackSet.Include(a => a.Items)
                                           .SingleOrDefault(a => a.BuildingId == building.ID && a.Period == dt);
                if (managementPackReport != null)
                {
                    tbComments.Text = managementPackReport.Commments;

                    _TableOfContents.Clear();
                    foreach (var item in managementPackReport.Items.OrderBy(a => a.Position))
                    {
                        if (item.IsTempFile)
                        {
                            var reportFileName = Path.GetTempFileName();
                            item.Path = reportFileName;
                            File.WriteAllBytes(item.Path, item.FileData);
                        }

                        if (File.Exists(item.Path))
                        {
                            _TableOfContents.Add(new TableOfContentForPdfRecord()
                            {
                                Path         = item.Path,
                                File         = item.File,
                                Description  = item.Description,
                                Description2 = item.Description2,
                                Pages        = item.Pages,
                                Position     = item.Position,
                                FileDate     = item.FileDate,
                                IsTempFile   = item.IsTempFile,
                                IncludeInTOC = true
                            });
                        }
                        else
                        {
                            Controller.ShowMessage("File: " + item.Path + " is missing or does not exist, item skipped.");
                        }
                    }
                }
            }

            if (_TableOfContents != null)
            {
                _TableOfContents = _TableOfContents.OrderBy(a => a.Position).ToList();
            }
        }
        private void btnSupplierLookup_Click(object sender, EventArgs e)
        {
            if (cmbBuilding.SelectedIndex < 0)
            {
                Controller.HandleError("Please select a building first.", "Validation Error");
                return;
            }
            var building   = cmbBuilding.SelectedItem as Building;
            var buildingId = building.ID;

            using (var context = SqlDataHandler.GetDataContext())
            {
                var frmSupplierLookup = new Astrodon.Forms.frmSupplierLookup(context, buildingId);

                var dialogResult = frmSupplierLookup.ShowDialog();
                var supplier     = frmSupplierLookup.SelectedSupplier;

                if (dialogResult == DialogResult.OK && supplier != null)
                {
                    _Supplier           = supplier;
                    lbSupplierName.Text = _Supplier.CompanyName;


                    var bankDetails = context.SupplierBuildingSet
                                      .Include(a => a.Bank)
                                      .SingleOrDefault(a => a.BuildingId == buildingId && a.SupplierId == _Supplier.id);
                    if (bankDetails == null)
                    {
                        Controller.HandleError("Supplier banking details for this building is not configured.\n" +
                                               "Please capture bank details for this building on the suppier detail screen.", "Validation Error");


                        var frmSupplierDetail = new Astrodon.Forms.frmSupplierDetail(context, _Supplier.id, buildingId);
                        frmSupplierDetail.ShowDialog();

                        bankDetails = context.SupplierBuildingSet
                                      .Include(a => a.Bank)
                                      .SingleOrDefault(a => a.BuildingId == buildingId && a.SupplierId == _Supplier.id);
                        if (bankDetails == null)
                        {
                            _Supplier = null;
                            return;
                        }
                    }

                    lbBankName.Text      = bankDetails.Bank.Name + " (" + bankDetails.BranceCode + ")";
                    lbAccountNumber.Text = bankDetails.AccountNumber;
                    btnSave.Enabled      = true;
                }
                else
                {
                    ClearSupplier();
                }
            }
        }
 private void LoadBuildings()
 {
     using (var context = SqlDataHandler.GetDataContext())
     {
         buildings = context.tblBuildings.Where(a => a.BuildingFinancialsEnabled &&
                                                a.BuildingDisabled == false &&
                                                (a.FinancialStartDate == null || a.FinancialStartDate <= DateTime.Today) &&
                                                (a.FinancialEndDate == null || a.FinancialEndDate >= DateTime.Today)
                                                ).ToList();
     }
 }
        private void btnDecline_Click(object sender, EventArgs e)
        {
            if (_SelectedItem == null)
            {
                Controller.HandleError("Please select an item from the list.", "Validation Error");
                return;
            }
            if (String.IsNullOrWhiteSpace(tbComments.Text))
            {
                Controller.HandleError("Please provide a reason for declining the report.", "Validation Error");
                return;
            }

            Cursor = Cursors.WaitCursor;
            try
            {
                Application.DoEvents();

                using (var context = SqlDataHandler.GetDataContext())
                {
                    var dataItem = context.ManagementPackSet.Single(a => a.id == _SelectedItem.Id);
                    dataItem.Commments         = tbComments.Text;
                    dataItem.Declined          = true;
                    dataItem.SubmitForApproval = false;
                    _SelectedItem.Comments     = tbComments.Text;
                    _SelectedItem.Processed    = true;

                    string emailContent = Controller.ReadResourceString("Astrodon.Reports.ManagementPack.ManagementPackDeclined.txt");
                    emailContent = emailContent.Replace("{NAME}", _SelectedItem.UserCreated);
                    emailContent = emailContent.Replace("{BUILDINGNAME}", _SelectedItem.Building);
                    emailContent = emailContent.Replace("{PERIOD}", _SelectedItem.Period.ToString("MMM yyyy"));
                    emailContent = emailContent.Replace("{COMMENTS}", _SelectedItem.Comments);

                    string[] toEmail = { _SelectedItem.UserCreatedEmail };
                    string   status;
                    if (!Mailer.SendDirectMail(Controller.user.email, toEmail, "", "", _SelectedItem.Building + "financial pack declined.", emailContent, false, out status))
                    {
                        Controller.HandleError("Unable to send notification email : " + status);
                    }

                    context.SaveChanges();
                    BindDataGrid();
                    ClosePDF();
                }
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        private void LoadAllUsers()
        {
            using (var context = SqlDataHandler.GetDataContext())
            {
                var users = from u in context.tblUsers
                            where u.Active
                            select u;

                _Users = users.OrderBy(a => a.name).ToList();
            }

            cbUserInvites.DataSource    = _Users;
            cbUserInvites.DisplayMember = "name";
            cbUserInvites.ValueMember   = "id";
        }
        private void button2_Click(object sender, EventArgs e)
        {
            var building     = cmbBuilding.SelectedItem as Building;
            var buildingName = "";

            using (var context = SqlDataHandler.GetDataContext())
            {
                buildingName = context.tblBuildings
                               .FirstOrDefault(a => a.id == building.ID)?.DataFolder;
            }
            if (Directory.Exists(buildingName))
            {
                dlgOpen.InitialDirectory = buildingName;
            }
            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                button2.Enabled = false;
                try
                {
                    var totalPages = GetTotalPages(dlgOpen.FileName);
                    if (totalPages > 0)
                    {
                        var fileDate = File.GetCreationTime(dlgOpen.FileName);

                        _TableOfContents.Insert(0, new TableOfContentForPdfRecord()
                        {
                            Path         = dlgOpen.FileName,
                            File         = Path.GetFileName(dlgOpen.FileName),
                            Position     = -1,
                            Pages        = totalPages,
                            FileDate     = fileDate,
                            IncludeInTOC = true
                        });

                        RefreshTOC();
                    }
                    else
                    {
                        MessageBox.Show("Corrupted file selected. Please select another file.");
                    }
                }
                finally
                {
                    button2.Enabled = true;
                }
            }
        }
        private void LoadUnpaidRequisitions()
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                using (var context = SqlDataHandler.GetDataContext())
                {
                    DateTime startDate = DateTime.Today.AddDays(-7);

                    var q = from r in context.tblRequisitions
                            join u in context.tblUsers on r.userID equals u.id
                            join b in context.tblBuildings on r.building equals b.id
                            where r.paid == false && r.processed == true &&
                            r.trnDate <= startDate &&
                            b.BuildingDisabled == false &&
                            u.Active == true
                            select new RequistitionGridItem
                    {
                        Id              = r.id,
                        User            = u.username,
                        TransactionDate = r.trnDate,
                        Building        = b.Building,
                        Amount          = r.amount,
                        Account         = r.account,
                        Ledger          = r.ledger,
                        Reference       = r.reference,
                        Payreference    = r.payreference,
                        Contractor      = r.contractor,
                        Supplier        = r.SupplierId == null ? string.Empty : r.Supplier.CompanyName,
                        InvoiceNumber   = r.InvoiceNumber,
                        InvoiceDate     = r.InvoiceDate,
                        BankName        = r.BankName,
                        AccountNumber   = r.AccountNumber,
                        BuildingCode    = b.Code,
                        ReqBatchNumber  = r.RequisitionBatchId == null ? 0 : r.RequisitionBatch.BatchNumber,
                        Paid            = false
                    };

                    _DataItems = q.OrderBy(a => a.Building).ThenByDescending(a => a.TransactionDate).ToList();
                    LoadGrid();
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
Example #16
0
        private void LoadSupplierList()
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                var building = cmbBuilding.SelectedItem as Building;
                if (building == null)
                {
                    return;
                }

                using (var context = SqlDataHandler.GetDataContext())
                {
                    var q = from s in context.SupplierBuildingSet
                            where s.BuildingId == building.ID
                            select new SupplierBuildingItem
                    {
                        Id = s.id,
                        BuildingAccountNumber = s.Building.bankAccNumber,
                        BuldingAccountName    = s.Building.accName,
                        Supplier      = s.Supplier.CompanyName,
                        Bank          = s.Bank.Name,
                        BranchCode    = s.BranceCode,
                        BranchName    = s.BranchName,
                        AccountNumber = s.AccountNumber,
                        BeneficiaryReferenceNumber    = s.BeneficiaryReferenceNumber,
                        OldBeneficiaryReferenceNumber = s.BeneficiaryReferenceNumber
                    };

                    if (cbAllSuppliers.Checked)
                    {
                        _SupplierList = q.OrderBy(a => a.Supplier).ToList();
                    }
                    else
                    {
                        _SupplierList = q.Where(a => a.BeneficiaryReferenceNumber == null).OrderBy(a => a.Supplier).ToList();
                    }
                    LoadSupplierGrid();
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        private static byte[] CreateNedbankCSV(tblBuilding building, RequisitionBatch batch, out string fileName)
        {
            fileName = null;


            string fromAccountNumber           = building.bankAccNumber;
            string fromAccountDescription      = building.accName;
            string fromAccountSubAccountNumber = string.Empty;

            using (var context = SqlDataHandler.GetDataContext())
            {
                var q = from r in context.tblRequisitions
                        where r.RequisitionBatchId == batch.id &&
                        r.UseNedbankCSV == true
                        select new NedbankCSVRecord
                {
                    FromAccountNumber               = fromAccountNumber,
                    FromAccountDescription          = fromAccountDescription,
                    MyStatementDescription          = r.payreference,
                    BeneficiaryReferenceNumber      = r.NedbankCSVBenificiaryReferenceNumber,
                    BeneficiaryStatementDescription = r.payreference,
                    Amount = r.amount
                };
                var transactions = q.ToList();

                //var csvFile = new NedbankCSVFile(transactions);

                using (MemoryStream fs = new MemoryStream())
                {
                    using (StreamWriter tw = new StreamWriter(fs))
                    {
                        foreach (var t in transactions)
                        {
                            tw.WriteLine(t.ToString());
                        }
                    }

                    byte[] result = new byte[fs.Length];
                    fs.Flush();
                    fs.Read(result, 0, result.Length);
                    fileName = "Nedbank - " + building.Code + "-" + batch.BatchNumber.ToString().PadLeft(6, '0') + ".csv";
                    return(result);
                }
            }
        }
 private void DeleteItem(int id)
 {
     if (Controller.AskQuestion("Are you sure you want to delete this entry?"))
     {
         using (var context = SqlDataHandler.GetDataContext())
         {
             var itm = context.BuildingCalendarEntrySet.Single(a => a.id == id);
             foreach (var invite in itm.UserInvites)
             {
                 context.CalendarUserInviteSet.Remove(invite);
             }
             context.BuildingCalendarEntrySet.Remove(itm);
             context.SaveChanges();
         }
         LoadGrid();
         GotoReadOnly();
     }
 }
        private void LoadPendingRequisions()
        {
            this.axAcroPDF1.Visible = false;
            using (var context = SqlDataHandler.GetDataContext())
            {
                var buildingIds = _Buildings.Select(a => a.ID).ToArray();

                var qry = from b in context.tblBuildings
                          join r in context.tblRequisitions on b.id equals r.building
                          join pmUser in context.tblUsers on b.pm equals pmUser.email
                          where r.processed == false &&
                          b.BuildingDisabled == false &&
                          pmUser.Active
                          select new RequisitionItem()
                {
                    RequisitionId     = r.id,
                    Building          = b.Building,
                    BuildingCode      = b.Code,
                    Bank              = r.BankName,
                    BranchCode        = r.BranchCode,
                    AccountNumber     = r.AccountNumber,
                    SupplierName      = r.Supplier != null ? r.Supplier.CompanyName : r.contractor,
                    LedgerAccount     = r.ledger,
                    Amount            = r.amount,
                    SupplierReference = r.payreference,
                    InvoiceNumber     = r.InvoiceNumber,
                    PortfolioManager  = pmUser.name,
                    PortfolioUserId   = pmUser.id,
                    InvoiceCount      = r.Documents.Count(a => a.IsInvoice == true),
                };

                if (_allBuildings)
                {
                    _PendingRequisitions = qry.OrderBy(a => a.Building).ThenBy(a => a.SupplierName).ToList();
                }
                else
                {
                    _PendingRequisitions = qry.Where(a => a.PortfolioUserId == Controller.user.id).OrderBy(a => a.Building).ThenBy(a => a.SupplierName).ToList();
                }

                LoadPendingRequisitionsGrid();
            }
        }
Example #20
0
        private void SearchTransactions()
        {
            searchStopped = false;
            using (var context = SqlDataHandler.GetDataContext())
            {
                var buildings = context.tblBuildings.ToList();

                foreach (var building in buildings)
                {
                    if (searchStopped)
                    {
                        break;
                    }

                    lblSearchStatus.Text = "Searching Building" + " " + building.Building;
                    Application.DoEvents();

                    using (var reportService = ReportServiceClient.CreateInstance())
                    {
                        try
                        {
                            DateTime fromDate    = new DateTime(dtpFromDate.Value.Year, dtpFromDate.Value.Month, dtpFromDate.Value.Day, 0, 0, 0);
                            DateTime toDate      = new DateTime(dtpToDate.Value.Year, dtpToDate.Value.Month, dtpToDate.Value.Day, 23, 59, 59);
                            string   reference   = tbReferenceContains.Text;
                            string   description = tbDescriptionContains.Text;
                            decimal  temp;
                            decimal? minimumAmount = decimal.TryParse(tbMinAmount.Text, out temp) ? temp : (decimal?)null;
                            decimal? maximumAmount = decimal.TryParse(tbMaxAmount.Text, out temp) ? temp : (decimal?)null;

                            var buildingResult = reportService.SearchPastel(building.DataPath, fromDate, toDate, reference, description, minimumAmount, maximumAmount);
                            _AllResults.AddRange(buildingResult);
                            UpdateDataGrid();
                        }
                        catch (Exception ex)
                        {
                            //  Controller.HandleError(ex.Message);
                        }
                    }
                }

                lblSearchStatus.Text = "Search Complete!";
            }
        }
        private void btnFindSupplier_Click(object sender, EventArgs e)
        {
            _SelectedSupplier   = null;
            lbSupplierName.Text = "";

            using (var context = SqlDataHandler.GetDataContext())
            {
                var building = cmbBuilding.SelectedItem as Building;

                var frmSupplierLookup = new frmSupplierLookup(context, building == null || building.ID == 0 ? (int?)null : building.ID);
                var supplierResult    = frmSupplierLookup.ShowDialog();
                var supplier          = frmSupplierLookup.SelectedSupplier;
                if (supplierResult == DialogResult.OK && supplier != null)
                {
                    _SelectedSupplier   = supplier;
                    lbSupplierName.Text = supplier.CompanyName;
                }
            }
        }
Example #22
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (_SupplierList == null)
            {
                return;
            }

            var itemsToSave = _SupplierList.Where(a => a.BeneficiaryReferenceNumber != a.OldBeneficiaryReferenceNumber).ToList();

            if (itemsToSave.Count > 0 && Controller.AskQuestion("Are you sure you want to update " + itemsToSave.Count() + " benificiaries?"))
            {
                this.Cursor = Cursors.WaitCursor;
                try
                {
                    using (var context = SqlDataHandler.GetDataContext())
                    {
                        foreach (var src in itemsToSave)
                        {
                            var bankEntry = context.SupplierBuildingSet.Single(a => a.id == src.Id);
                            var audit     = new Astrodon.Data.SupplierData.SupplierBuildingAudit()
                            {
                                SupplierBuildingId = bankEntry.id,
                                FieldName          = "BeneficiaryReferenceNumber",
                                OldValue           = bankEntry.BeneficiaryReferenceNumber,
                                NewValue           = src.BeneficiaryReferenceNumber,
                                AuditTimeStamp     = DateTime.Now,
                                UserId             = Controller.user.id
                            };
                            context.SupplierBuildingAuditSet.Add(audit);
                            bankEntry.BeneficiaryReferenceNumber = src.BeneficiaryReferenceNumber;
                        }
                        context.SaveChanges();
                    }
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
                Application.DoEvents();
                LoadSupplierList();
            }
        }
        private void LoadMeetingRooms()
        {
            using (var context = SqlDataHandler.GetDataContext())
            {
                var rooms = context.MeetingRoomSet.Where(a => a.Active).ToList();
                _MeetingRooms = rooms.Select(a => new IdValue()
                {
                    Id    = a.id,
                    Value = a.ToString()
                }).OrderBy(a => a.Value).ToList();
            }

            cbFilterRoom.DataSource    = _MeetingRooms;
            cbFilterRoom.ValueMember   = "Id";
            cbFilterRoom.DisplayMember = "Value";

            cbRoom.DataSource    = _MeetingRooms;
            cbRoom.ValueMember   = "Id";
            cbRoom.DisplayMember = "Value";
        }
        private void DeleteRequisition(RequistitionGridItem item)
        {
            if (item == null || item.Paid)
            {
                return;
            }

            if (Controller.AskQuestion("Are you sure you want to delete this requisition?"
                                       + Environment.NewLine + item.ToString()))
            {
                using (var context = SqlDataHandler.GetDataContext())
                {
                    context.DeleteRequisition(item.Id);
                    _DataItems.Remove(item);
                    var bindingSource = new BindingSource();
                    bindingSource.DataSource = _DataItems;
                    dgItems.DataSource       = bindingSource;
                }
            }
        }
        private void LoadPMUsers()
        {
            using (var context = SqlDataHandler.GetDataContext())
            {
                var pmsQ = from b in context.tblBuildings
                           join u in context.tblUsers on b.pm equals u.email
                           where b.BuildingDisabled == false
                           select new IdValue()
                {
                    Id    = u.id,
                    Value = u.name
                };

                _PMUsers = pmsQ.Distinct().OrderBy(a => a.Value).ToList();
            }

            cbPM.DataSource    = _PMUsers;
            cbPM.ValueMember   = "Id";
            cbPM.DisplayMember = "Value";
        }
        private void btnSaveInstructions_Click(object sender, EventArgs e)
        {
            var specialInstructions = txtSpecialInstructions.Text;
            var supplierName        = lblSupplierNameEdit.Text;

            if (String.IsNullOrWhiteSpace(specialInstructions) && String.IsNullOrWhiteSpace(supplierName))
            {
                Controller.HandleError("Please select a supplier to edit", "Validation Error");
            }
            else
            {
                using (var context = SqlDataHandler.GetDataContext())
                {
                    var supplier = context.SupplierBuildingSet.Single(a => a.SupplierId == _SelectedSupplier.SupplierId && _BuildingId == a.BuildingId);
                    supplier.SpecialInstructions = specialInstructions;
                    context.SaveChanges();
                }
                LoadSuppliers((cmbBuilding.SelectedItem as Building).ID);
            }
        }
 private void MarkAsPaid(RequistitionGridItem item)
 {
     if (item != null && item.Paid == false)
     {
         if (Controller.AskQuestion("Are you sure you want to mark this item as Paid?"
                                    + Environment.NewLine + item.ToString()))
         {
             using (var context = SqlDataHandler.GetDataContext())
             {
                 var req = context.tblRequisitions.Single(a => a.id == item.Id);
                 req.paid            = true;
                 req.PaymentDataPath = "Manual-" + Controller.user.username + "-" + DateTime.Now.ToString("yyyy/MM/dd HH:mm");
                 context.SaveChanges();
                 _DataItems.Remove(item);
                 var bindingSource = new BindingSource();
                 bindingSource.DataSource = _DataItems;
                 dgItems.DataSource       = bindingSource;
             }
         }
     }
 }
        private void DeleteJob(int jobID)
        {
            if (Controller.UserIsSheldon())
            {
                if (Controller.AskQuestion("Are you sure you want to delete job " + jobID.ToString()))
                {
                    using (var context = SqlDataHandler.GetDataContext())
                    {
                        var job = context.tblJobs.Single(a => a.id == jobID);

                        var jobAttachments = context.tblJobAttachments.Where(a => a.jobID == jobID).ToList();
                        if (jobAttachments.Count > 0)
                        {
                            context.tblJobAttachments.RemoveRange(jobAttachments);
                        }

                        var jobCustomers = context.tblJobCustomers.Where(a => a.jobID == jobID).ToList();
                        if (jobCustomers.Count > 0)
                        {
                            context.tblJobCustomers.RemoveRange(jobCustomers);
                        }

                        var jobStatus = context.tblJobStatus.Where(a => a.jobID == jobID).ToList();
                        if (jobCustomers.Count > 0)
                        {
                            context.tblJobStatus.RemoveRange(jobStatus);
                        }

                        context.tblJobs.Remove(job);

                        context.SaveChanges();
                        Controller.ShowMessage("Job deleted.");
                    }
                }
            }
            else
            {
                Controller.HandleError("You are not allowed to delete jobs");
            }
        }
 private void LoadCheckLists()
 {
     using (var context = SqlDataHandler.GetDataContext())
     {
         var itms     = context.ManagementPackTOCItemSet.ToList();
         var tmpItems = new List <string>()
         {
             "Detail income statement",
             "Balance sheet",
             "Bank statement",
             "Sundry customers",
             "Sundry suppliers",
             "Council reconciliations",
             "Cash movement statement",
             "Levy Roll",
             "Financial checklist",
             "Invoicing",
             "POP",
             "Maintenance"
         };
         if (itms == null || itms.Count < tmpItems.Count())
         {
             foreach (var itm in tmpItems)
             {
                 context.ManagementPackTOCItemSet.Add(new Data.ManagementPackData.ManagementPackTOCItem()
                 {
                     Description = itm
                 });
             }
             context.SaveChanges();
             _DescriptionList = tmpItems.OrderBy(a => a).ToList();
         }
         else
         {
             _DescriptionList = itms.OrderBy(a => a.Description).Select(a => a.Description).ToList();
         }
     }
     _DescriptionList.Insert(0, "");
 }
        private void LoadSuppliers(int buildingId)
        {
            using (var context = SqlDataHandler.GetDataContext())
            {
                _PreferredSupplierResults = (from s in context.SupplierSet
                                             join sbTemp in context.SupplierBuildingSet on s.id equals sbTemp.SupplierId into sbJoin
                                             from sb in sbJoin.DefaultIfEmpty()

                                             where sb.BuildingId == buildingId

                                             select new PreferredSupplierResult
                {
                    CompanyName = s.CompanyName,
                    ContactPerson = s.ContactPerson,
                    ContactNumber = s.ContactNumber,
                    SpecialInstructions = sb.SpecialInstructions,
                    BuildingId = sb.BuildingId,
                    SupplierId = sb.SupplierId
                }).ToList();
            }

            BindDataGrid();
        }