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;
                }
            }
        }
示例#2
0
        private void dgMaintenance_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid      = (DataGridView)sender;
            var editColumnIndex = 0;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                var selectedItem = senderGrid.Rows[e.RowIndex].DataBoundItem as MaintenanceResult;

                if (selectedItem != null)
                {
                    if (e.ColumnIndex == editColumnIndex)
                    {
                        if (selectedItem.MaintenanceId != null)
                        {
                            var frmMaintenanceDetail = new frmMaintenanceDetail(_DataContext, selectedItem.MaintenanceId.Value, false);
                            var dialogResult         = frmMaintenanceDetail.ShowDialog();

                            if (dialogResult == DialogResult.OK)
                            {
                                btnSearch.PerformClick();
                            }
                        }
                        else
                        {
                            var reqItem    = _DataContext.tblRequisitions.Where(a => a.id == selectedItem.RequisitionId).Single();
                            var configItem = _DataContext.BuildingMaintenanceConfigurationSet.Single(a => a.id == selectedItem.ConfigItemId.Value);

                            if (reqItem.SupplierId == null)
                            {
                                //lets find the supplier id


                                var frmSupplierLookup = new frmSupplierLookup(_DataContext, configItem.BuildingId);

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

                                if (supplierResult == DialogResult.OK && supplier != null)
                                {
                                    var bankDetails = _DataContext.SupplierBuildingSet.Include(a => a.Bank).SingleOrDefault(a => a.BuildingId == configItem.BuildingId && a.SupplierId == supplier.id);
                                    if (bankDetails != null)
                                    {
                                        reqItem.SupplierId    = supplier.id;
                                        reqItem.Supplier      = supplier;
                                        reqItem.BankName      = bankDetails.Bank.Name;
                                        reqItem.BranchCode    = bankDetails.BranceCode;
                                        reqItem.BranchName    = bankDetails.BranchName;
                                        reqItem.AccountNumber = bankDetails.AccountNumber;
                                    }
                                    else
                                    {
                                        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");
                                        return;
                                    }
                                }
                                else
                                {
                                    Controller.HandleError("Supplier required for Maintenance. Please select a supplier.", "Validation Error");
                                    return;
                                }
                            }

                            var frmMaintenanceDetail = new frmMaintenanceDetail(_DataContext, reqItem, configItem, true);
                            var dialogResult         = frmMaintenanceDetail.ShowDialog();
                            if (dialogResult == DialogResult.OK)
                            {
                                _DataContext.SaveChanges();
                                btnSearch.PerformClick();
                            }
                            else
                            {
                                //reject changes
                                foreach (var entry in _DataContext.ChangeTracker.Entries())
                                {
                                    switch (entry.State)
                                    {
                                    case EntityState.Modified:
                                    case EntityState.Deleted:
                                        entry.State = EntityState.Modified;     //Revert changes made to deleted entity.
                                        entry.State = EntityState.Unchanged;
                                        break;

                                    case EntityState.Added:
                                        entry.State = EntityState.Detached;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        private void btnSupplierLookup_Click(object sender, EventArgs e)
        {
            using (var context = SqlDataHandler.GetDataContext())
            {
                var frmSupplierLookup = new frmSupplierLookup(context);
                var dialogResult      = frmSupplierLookup.ShowDialog();
                var supplier          = frmSupplierLookup.SelectedSupplier;

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

                    int[] buildings = _Buildings.Select(a => a.ID).ToArray();

                    DateTime invoiceDate = dtInvoiceDate.Value;


                    var q = from sb in context.SupplierBuildingSet
                            join b in context.tblBuildings on sb.BuildingId equals b.id
                            join bank in context.BankSet on sb.BankId equals bank.id
                            join s in context.SupplierSet on sb.SupplierId equals s.id
                            where s.id == _Supplier.id &&
                            buildings.Contains(b.id) &&
                            b.BuildingDisabled == false
                            select new BuildingRequisitionItem()
                    {
                        BuildingId                = b.id,
                        BuildingName              = b.Building,
                        BuildingAbreviatio        = b.Code,
                        BuildingTrustAccount      = b.AccNumber,
                        BuildingDataPath          = b.DataPath,
                        InvoiceDate               = invoiceDate,
                        SupplierBankAccount       = sb.AccountNumber,
                        SupplierBank              = bank.Name,
                        InvoiceAttachmentRequired = _AttachmentRequired,
                        BranchCode                = bank.BranchCode,
                        BranchName                = bank.BranchName,
                        BankId            = bank.id,
                        BankAlreadyLinked = true,
                        OwnTrustAccount   = "OWN",
                        IsOwnAccount      = b.bank == "OWN" ? true : false,
                        Building          = b
                    };

                    _SupplierBuildingList = q.ToList();

                    //now add all the buildings not in the list
                    int[] exclude     = _SupplierBuildingList.Select(a => a.BuildingId).Distinct().ToArray();
                    int[] buldingList = buildings.Except(exclude).ToArray();

                    var q2 = from b in context.tblBuildings
                             where buldingList.Contains(b.id) &&
                             b.BuildingDisabled == false
                             select new BuildingRequisitionItem()
                    {
                        BuildingId                = b.id,
                        BuildingName              = b.Building,
                        BuildingAbreviatio        = b.Code,
                        BuildingTrustAccount      = b.AccNumber,
                        BuildingDataPath          = b.DataPath,
                        InvoiceDate               = invoiceDate,
                        InvoiceAttachmentRequired = _AttachmentRequired,
                        BankId = null,
                        SupplierBankAccount = null,
                        SupplierBank        = null,
                        BranchCode          = null,
                        BranchName          = null,
                        BankAlreadyLinked   = false,
                        OwnTrustAccount     = "OWN",
                        IsOwnAccount        = b.bank == "OWN" ? true : false,
                        Building            = b
                    };

                    _SupplierBuildingList.AddRange(q2.ToList());

                    _SupplierBuildingList = _SupplierBuildingList.OrderBy(a => a.BuildingName).ToList();

                    var qBank = from sb in context.SupplierBuildingSet
                                where sb.SupplierId == supplier.id
                                select new SupplierBankAccountDetail()
                    {
                        BankId        = sb.BankId,
                        BankName      = sb.Bank.Name,
                        BranchCode    = sb.BranceCode,
                        AccountNumber = sb.AccountNumber,
                        BranchName    = sb.BranchName
                    };

                    _SupplierBankAccounts               = qBank.Distinct().OrderBy(a => a.BankName).ToList();
                    cbSupplierBankAccount.DataSource    = _SupplierBankAccounts;
                    cbSupplierBankAccount.ValueMember   = "BankId";
                    cbSupplierBankAccount.DisplayMember = "DisplayString";
                    if (_SupplierBankAccounts.Count > 0)
                    {
                        cbSupplierBankAccount.SelectedIndex = 0;
                    }
                    else
                    {
                        cbSupplierBankAccount.SelectedIndex = -1;
                    }

                    LoadBuildingsGrid();
                }
                else
                {
                    ClearSupplier();
                }
            }
        }