Exemple #1
0
        private void dgvAllBookings_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                bool value = Conversions.ToBoolean(dgvAllBookings.Rows[e.RowIndex].Cells[0].Value);
                VW_BookingMinibooking mbRow;
                VW_UnitSourceMiniUnit muRow;
                mbRow = (VW_BookingMinibooking)dgvAllBookings.Rows[e.RowIndex].DataBoundItem;
                if (value == false)
                {
                    dgvAllBookings.Rows[e.RowIndex].Cells[0].Value = true;
                    numbSelectMU = +1;
                    // selectedUnits.Add(muID, MUSource)

                    // Check if mini unit is already assigned to mini booking
                    for (int i = 0, loopTo = dgvMiniUnit.Rows.Count - 1; i <= loopTo; i++)
                    {
                        muRow = (VW_UnitSourceMiniUnit)dgvMiniUnit.Rows[i].DataBoundItem;

                        // check if mu was already assigned
                        if (Information.IsNothing(muRow.CommodityId) || muRow.CommodityId == 0)
                        {
                            var result = My.MyProject.Forms.MessageBoxCeresYesNo.ShowDialog("Warning:", "There's no commodity added to the unit '" + muRow.MiniunitNumber + "' Yet. Would you like to add it now? " + "If No is selected, the unit will not be added to the booking", My.Resources.Resources.caution, this);
                            if (result == DialogResult.Yes)
                            {
                                My.MyProject.Forms.FrmEditAddRailList.isNewRecord = false;
                                var unit     = UnitSourceService.GetVWById(muRow.UnitSourceId);
                                var unitList = new List <VW_UnitSource>();
                                unitList.Add(unit);
                                My.MyProject.Forms.FrmEditAddRailList.isMultiEdit = false;
                                My.MyProject.Forms.FrmEditAddRailList.isNewRecord = false;
                                My.MyProject.Forms.FrmEditAddRailList.LoadForm(unitList);
                                Close();
                                MdlLoadingSetting.showDialogForm(My.MyProject.Forms.FrmEditAddRailList, My.MyProject.Forms.FrmParentScreen);
                            }
                            else
                            {
                                shouldNotAssignList.Add(muRow.ToString() + "|" + mbRow.MiniBookingId.ToString());
                            }
                        }
                        // If cmdty and grade doesnt exist in mb, ask if should add.

                        else if (MdlBookingManagement.miniUnitMissingCommodity(mbRow.MiniBookingId, muRow.CommodityId, muRow.GradeId))
                        {
                            var result = My.MyProject.Forms.MessageBoxCeresYesNo.ShowDialog("Commodity and Rate doesn't match", "The commodity and grade of the unit '" + muRow.MiniunitNumber + "' (" + muRow.GradeCode + " " + muRow.CommodityCode + ") is not added to the booking '" + mbRow.BookingNumber + "'. Would you like to add it now? " + "If No is selected, the unit will not be added to the booking", My.Resources.Resources.caution, this);
                            if (result == DialogResult.Yes)
                            {
                                MdlBookingManagement.saveBkgCommodity(mbRow.MiniBookingId, muRow.CommodityId, muRow.GradeId);
                                getCmdyAndGrades(mbRow.MiniBookingId);
                                // muRow =
                                //VWUnitSourceMiniUnitBindingSource.DataSource.Item(muRow) = MiniUnitService.GetVWByMUId(muRow.MiniUnitId);
                            }
                            else
                            {
                                shouldNotAssignList.Add(muRow.MiniUnitId.ToString() + "|" + mbRow.MiniBookingId.ToString());
                            }
                        }
                        else if (MdlBookingManagement.miniUnitAlreadyAssigned(muRow.MiniUnitId, mbRow.MiniBookingId, Conversions.ToBoolean(0)))
                        {
                            shouldNotAssignList.Add(muRow.MiniUnitId.ToString() + "|" + mbRow.MiniBookingId.ToString());
                            My.MyProject.Forms.MessageBoxCeresOK.ShowDialog("Unit source already added to booking", "Selected Unit source is already added to the booking " + mbRow.BookingNumber + ", so it will not be added again.", this);
                        }
                        // If cmdty and grade doesnt exist in mb, ask if should add.

                        if (mbRow.CustomerId != muRow.CustomerId)
                        {
                            var result = My.MyProject.Forms.MessageBoxCustomerMatchingWarning.ShowDialog(mbRow, muRow, this);
                            if (result == DialogResult.Yes & shouldChangeCustomer == true)
                            {
                                muRow.CustomerId = mbRow.CustomerId;
                                MdlBookingManagement.updateCustomer(MiniUnitService.GetById(muRow.MiniUnitId));
                            }
                            else
                            {
                                shouldNotAssignList.Add(muRow.MiniUnitId.ToString() + "|" + mbRow.MiniBookingId.ToString());
                            }
                        }
                    }
                }
                else
                {
                    dgvAllBookings.Rows[e.RowIndex].Cells[0].Value = false;
                    numbSelectMU = -1;
                    for (int i = 0, loopTo1 = dgvMiniUnit.Rows.Count - 1; i <= loopTo1; i++)
                    {
                        muRow = (VW_UnitSourceMiniUnit)dgvMiniUnit.Rows[i].DataBoundItem;
                        shouldNotAssignList.Remove(muRow.MiniUnitId.ToString() + "|" + mbRow.MiniBookingId.ToString());
                    }
                }
            }

            checkAsnButton();
        }
Exemple #2
0
        private void checkCmdtyAndCustomer(object unitRow)
        {
            int    muID;
            string MUSource;
            string cmdtyName;
            string gradeName;
            int    cmdtyId;
            int    gradeId;
            VW_BookingMinibooking selectedMBRow;
            VW_UnitSourceMiniUnit mu = (VW_UnitSourceMiniUnit)unitRow;

            VW_GrainUnitStorage g = new VW_GrainUnitStorage();

            try
            {
                g = (VW_GrainUnitStorage)unitRow;
            }
            catch { }


            muID = mu.MiniUnitId;


            MUSource = Conversions.ToString(mu.MiniunitNumber);

            // selectedUnits.Add(muID, MUSource)

            cmdtyName = Conversions.ToString(mu.CommodityName);
            gradeName = Conversions.ToString(mu.GradeName);
            cmdtyId   = Conversions.ToInteger(mu.CommodityId);
            gradeId   = Conversions.ToInteger(mu.GradeId);

            // Check if mini unit is already assigned to mini booking
            for (int i = 0, loopTo = dgvSelectedBkg.Rows.Count - 1; i <= loopTo; i++)
            {
                selectedMBRow = (VW_BookingMinibooking)dgvSelectedBkg.Rows[i].DataBoundItem;
                bool muAlreadyAsn;
                // check if mu was already assigned
                if (tabUnits.SelectedIndex == 0)
                {
                    muAlreadyAsn = MdlBookingManagement.miniUnitAlreadyAssigned(muID, selectedMBRow.MiniBookingId, false);
                }
                else
                {
                    g            = (VW_GrainUnitStorage)unitRow;
                    muAlreadyAsn = MdlBookingManagement.miniUnitAlreadyAssigned(g.GrainInvStorageLocationId, selectedMBRow.MiniBookingId, true);
                }

                if (muAlreadyAsn)
                {
                    shouldNotAssignList.Add(muID.ToString() + "|" + selectedMBRow.MiniBookingId.ToString());
                    My.MyProject.Forms.MessageBoxCeresOK.ShowDialog("Unit source already added to booking", "Selected Unit source is already added to the booking " + selectedMBRow.BookingNumber + ", so it will not be added again.", this);
                }

                // If cmdty doesn't exist, add to unit source.
                if (cmdtyId == 0)
                {
                    var result = My.MyProject.Forms.MessageBoxCeresYesNo.ShowDialog("Warning:", "There's no commodity added to the unit '" + MUSource + "' Yet. Would you like to add it now? " + "If No is selected, the unit will not be added to the booking", My.Resources.Resources.caution, this);
                    if (result == DialogResult.Yes)
                    {
                        var unit     = UnitSourceService.GetVWById(Conversions.ToInteger(mu.UnitSourceId));
                        var unitList = new List <VW_UnitSource>();
                        unitList.Add(unit);
                        My.MyProject.Forms.FrmEditAddRailList.isNewRecord = false;
                        My.MyProject.Forms.FrmEditAddRailList.isMultiEdit = false;
                        My.MyProject.Forms.FrmEditAddRailList.LoadForm(unitList);
                        Close();
                        MdlLoadingSetting.showDialogForm(My.MyProject.Forms.FrmEditAddRailList, My.MyProject.Forms.FrmParentScreen);
                    }
                    // If tabUnits.SelectedIndex = 0 Then
                    // VWUnitSourceMiniUnitBindingSource.DataSource.Item(unitRow) = MiniUnitService.GetVWByMUId(unitRow.MiniUnitId)
                    // 'VWUnitSourceMiniUnitBindingSource.DataSource

                    // End If
                    else if (tabUnits.SelectedIndex == 0)
                    {
                        shouldNotAssignList.Add(muID.ToString() + "|" + selectedMBRow.MiniBookingId.ToString());
                    }
                    else
                    {
                        g = (VW_GrainUnitStorage)unitRow;
                        shouldNotAssignStorageList.Add(g.GrainInvStorageLocationId.ToString() + "|" + selectedMBRow.MiniBookingId.ToString());
                    }
                }
                // If cmdty and grade doesnt exist in mb, ask if should add.
                else if (MdlBookingManagement.miniUnitMissingCommodity(selectedMBRow.MiniBookingId, cmdtyId, gradeId))
                {
                    var result = My.MyProject.Forms.MessageBoxCeresYesNo.ShowDialog("Commodity and Rate doesn't match", "The commodity and grade of the unit '" + MUSource + "' (" + gradeName + " " + cmdtyName + ") is not added to the booking '" + selectedMBRow.BookingNumber + "'. Would you like to add it now? " + "If No is selected, the unit will not be added to the booking", My.Resources.Resources.caution, this);
                    if (result == DialogResult.Yes)
                    {
                        MdlBookingManagement.saveBkgCommodity(selectedMBRow.MiniBookingId, cmdtyId, gradeId);
                    }
                    else if (tabUnits.SelectedIndex == 0)
                    {
                        shouldNotAssignList.Add(muID.ToString() + "|" + selectedMBRow.MiniBookingId.ToString());
                    }
                    else
                    {
                        shouldNotAssignStorageList.Add(g.GrainInvStorageLocationId.ToString() + "|" + selectedMBRow.MiniBookingId.ToString());
                    }
                }

                if (mu.CustomerId != selectedMBRow.CustomerId)
                {
                    var result = My.MyProject.Forms.MessageBoxCustomerMatchingWarning.ShowDialog(selectedMBRow, unitRow, this);
                    if (result == DialogResult.Yes & shouldChangeCustomer == true)
                    {
                        MdlBookingManagement.updateCustomer(MiniUnitService.GetById(muID));

                        // update muDataGridView
                        VWUnitSourceMiniUnitBindingSource.DataSource = VW_UnitSOurceMiniUnitService.GetByFilter(Conversions.ToString(mu.CustomerName), BkServicesList, Strings.Trim(tbSearchStorageUnit.Text));
                    }
                    else if (tabUnits.SelectedIndex == 0)
                    {
                        shouldNotAssignList.Add(muID.ToString() + "|" + selectedMBRow.MiniBookingId.ToString());
                    }
                    else
                    {
                        shouldNotAssignStorageList.Add(g.GrainInvStorageLocationId.ToString() + "|" + selectedMBRow.MiniBookingId.ToString());
                    }
                }
            }
        }