Exemplo n.º 1
0
 public DialogResult ShowEdit(GinLoadEntity doc)
 {
     dataObj = doc;
     //await LoadForm();
     this.Text = "Update Gin Load";
     return(this.ShowDialog());
 }
Exemplo n.º 2
0
        private void btnDeleteSelected_Click(object sender, EventArgs e)
        {
            try
            {
                using (var uow = UnitOfWorkFactory.CreateUnitOfWork())
                {
                    List <GinLoadEntity> itemsToDelete = new List <GinLoadEntity>();
                    BusyMessage.Show("Verifying loads can be deleted.", this.FindForm());
                    IEnumerable <string> undeletableIds = uow.GinLoadRepository.GetUndeletableIds();
                    int undeletableCount = undeletableIds.Count();
                    foreach (DataGridViewRow row in this.dataGridLoads.Rows)
                    {
                        GinLoadEntity item = (GinLoadEntity)row.DataBoundItem;
                        if (Convert.ToBoolean(row.Cells[0].Value))
                        {
                            itemsToDelete.Add(item);
                        }
                    }
                    BusyMessage.Close();

                    if (itemsToDelete.Count() > 0)
                    {
                        if (undeletableCount > 0)
                        {
                            if (MessageBox.Show(string.Format("{0} load(s) cannot be deleted because they are linked to other records. Would you like to continue and delete loads not linked?", undeletableCount), "Info", MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                return;
                            }
                            itemsToDelete.RemoveAll(doc => undeletableIds.Contains(doc.Id));
                        }

                        if (itemsToDelete.Count() > 0 && MessageBox.Show("Are you sure you want to delete the " + itemsToDelete.Count.ToString() + " selected load(s)? All modules and bales from this load will have load information removed and will no longer be linked to a load.", "Delete?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            BusyMessage.Show("Deleting...", this.FindForm());

                            uow.GinLoadRepository.BulkDelete(itemsToDelete);
                            uow.SaveChanges();
                            BusyMessage.Close();
                            refresh();
                        }
                    }
                    else
                    {
                        MessageBox.Show("No records were selected to delete.");
                    }
                }
            }
            catch (Exception exc)
            {
                Logging.Logger.Log(exc);
                MessageBox.Show("An error occurred deleting gin load(s).");
            }
        }
Exemplo n.º 3
0
        private void btnEditSelected_Click(object sender, EventArgs e)
        {
            var             dialog = new AddEditGinLoad();
            DataGridViewRow row    = null;

            if (dataGridLoads.SelectedRows.Count > 0)
            {
                row = dataGridLoads.SelectedRows[0];
                GinLoadEntity doc    = (GinLoadEntity)row.DataBoundItem;
                var           result = dialog.ShowEdit(doc);
                if (result != DialogResult.Cancel)
                {
                    refresh();
                }
            }
            else
            {
                MessageBox.Show("Please select a row to edit.");
            }
        }
Exemplo n.º 4
0
        private static void createPBIData()
        {
            FieldEntity  field  = null;
            ModuleEntity module = null;

            using (var uow = UnitOfWorkFactory.CreateUnitOfWork())
            {
                #region Create Modules and Gin Loads
                var client = new ClientEntity();
                client.Name  = "PBI TEST CLIENT";
                client.Farms = new List <FarmEntity>();

                var farm = new FarmEntity();
                farm.Id     = Guid.NewGuid().ToString();
                farm.Name   = "PBI TEST FARM";
                farm.Fields = new List <FieldEntity>();

                field           = new FieldEntity();
                field.Id        = Guid.NewGuid().ToString();
                field.Name      = "PBI TEST FIELD";
                field.Modules   = new List <ModuleEntity>();
                field.Latitude  = 0.00;
                field.Longitude = 0.00;
                field.Created   = DateTime.UtcNow;
                farm.Fields.Add(field);

                client.Farms.Add(farm);
                uow.ClientRepository.Save(client);
                uow.SaveChanges();
            }

            //add modules from CSV file
            string   fileName       = "C:\\Users\\mbohn\\Documents\\PBI_TestData.csv";
            string[] moduleContents = System.IO.File.ReadAllLines(fileName);

            List <GinLoadEntity> ginLoadEntities = new List <GinLoadEntity>();
            int bridgeLoadNumber = 0;
            for (int moduleCount = 1; moduleCount < moduleContents.Length; moduleCount++)
            {
                var fields = moduleContents[moduleCount].Split(',');
                using (var uow = UnitOfWorkFactory.CreateUnitOfWork())
                {
                    module                 = new ModuleEntity();
                    module.Id              = Guid.NewGuid().ToString();
                    module.Name            = fields[0];
                    module.FieldId         = field.Id;
                    module.TruckID         = "";
                    module.Driver          = "";
                    module.LoadNumber      = fields[3];
                    module.HIDDiameter     = Decimal.Parse(fields[1]) * 2.54M;
                    module.HIDModuleWeight = Decimal.Parse(fields[2]) * 0.453592M;

                    module.Latitude      = 0.00;
                    module.Longitude     = 0.00;
                    module.ModuleStatus  = ModuleStatus.IN_FIELD;
                    module.Created       = DateTime.UtcNow;
                    module.ModuleHistory = new List <ModuleHistoryEntity>();
                    var historyItem = new ModuleHistoryEntity
                    {
                        Id              = Guid.NewGuid().ToString(),
                        Created         = DateTime.UtcNow,
                        Driver          = module.Driver,
                        TruckID         = module.TruckID,
                        Latitude        = module.Latitude,
                        Longitude       = module.Longitude,
                        ModuleEventType = ModuleEventType.IMPORTED_FROM_FILE
                    };
                    module.FieldId = field.Id;
                    module.ModuleHistory.Add(historyItem);
                    uow.ModuleRepository.Add(module);
                    uow.SaveChanges();

                    if (!ginLoadEntities.Any(g => g.GinTagLoadNumber == module.LoadNumber))
                    {
                        //create gin load
                        var affectedGinLoad = new GinLoadEntity();
                        ginLoadEntities.Add(affectedGinLoad);
                        affectedGinLoad.Created       = DateTime.UtcNow;
                        affectedGinLoad.SyncedToCloud = false;

                        affectedGinLoad.Name                  = module.LoadNumber;
                        affectedGinLoad.GinTagLoadNumber      = module.LoadNumber;
                        affectedGinLoad.ScaleBridgeLoadNumber = bridgeLoadNumber++;
                        affectedGinLoad.NetWeight             = Convert.ToDecimal(fields[4]);
                        affectedGinLoad.GrossWeight           = affectedGinLoad.NetWeight + 8200;
                        affectedGinLoad.SplitWeight1          = affectedGinLoad.NetWeight;
                        affectedGinLoad.SplitWeight2          = 0.00M;

                        affectedGinLoad.ScaleBridgeId         = "BRIDGE1";
                        affectedGinLoad.ScaleBridgeLoadNumber = ginLoadEntities.Count();
                        affectedGinLoad.Source        = InputSource.GIN;
                        affectedGinLoad.SyncedToCloud = false;
                        affectedGinLoad.TruckID       = "TRUCK1";
                        affectedGinLoad.YardLocation  = "SOMEWHERE";
                        affectedGinLoad.SubmittedBy   = "TEST HARNESS";

                        //add client/farm/field information
                        affectedGinLoad.FieldId = field.Id;
                        uow.GinLoadRepository.Save(affectedGinLoad);
                        uow.SaveChanges();

                        module.GinTagLoadNumber = affectedGinLoad.GinTagLoadNumber;
                        module.GinLoadId        = affectedGinLoad.Id;
                    }
                    else
                    {
                        var load = ginLoadEntities.Single(g => g.GinTagLoadNumber == module.LoadNumber);
                        module.GinTagLoadNumber = load.GinTagLoadNumber;
                        module.GinLoadId        = load.Id;
                    }

                    //create feeder scan of module
                    module.ModuleStatus = ModuleStatus.ON_FEEDER;
                    module.LastBridgeId = "BRIDGE2";
                    // uow.ModuleRepository.Save(module);
                    //uow.SaveChanges();
                    Console.WriteLine("CREATING FEEDER SCAN FOR MODULE : " + module.Name);
                    ModuleHistoryEntity feederHistoryItem = new ModuleHistoryEntity();
                    feederHistoryItem.Id               = Guid.NewGuid().ToString();
                    feederHistoryItem.Created          = DateTime.Parse(fields[5] + " " + fields[6]).ToUniversalTime();
                    feederHistoryItem.Created          = feederHistoryItem.Created.AddSeconds(int.Parse(fields[7]));
                    feederHistoryItem.Driver           = "";
                    feederHistoryItem.TruckID          = "";
                    feederHistoryItem.BridgeId         = "BRIDGE2";
                    feederHistoryItem.ModuleId         = module.Id;
                    feederHistoryItem.Latitude         = module.Latitude;
                    feederHistoryItem.Longitude        = module.Longitude;
                    feederHistoryItem.GinTagLoadNumber = module.GinTagLoadNumber;

                    if (!string.IsNullOrEmpty(module.BridgeLoadNumber))
                    {
                        feederHistoryItem.BridgeLoadNumber = bridgeLoadNumber;
                    }
                    else
                    {
                        feederHistoryItem.BridgeLoadNumber = null;
                    }

                    module.ModuleHistory.Add(feederHistoryItem);
                    feederHistoryItem.ModuleStatus    = ModuleStatus.ON_FEEDER;
                    feederHistoryItem.ModuleStatus    = module.ModuleStatus;
                    feederHistoryItem.ModuleEventType = ModuleEventType.BRIDGE_SCAN;
                    module.SyncedToCloud = false;
                    uow.ModuleRepository.Save(module);
                    uow.SaveChanges();
                }
            }

            #endregion

            #region Create PBIs
            using (var uow = UnitOfWorkFactory.CreateUnitOfWork())
            {
                string   pbiFileName = "C:\\Users\\mbohn\\Documents\\PBI_Test_Bales.csv";
                string[] pbiLines    = System.IO.File.ReadAllLines(pbiFileName);
                for (int lineCount = 1; lineCount < pbiLines.Length; lineCount++)
                {
                    string line         = pbiLines[lineCount];
                    var    pbiFields    = line.Split(',');
                    var    affectedBale = new BaleEntity();
                    affectedBale.Id              = Guid.NewGuid().ToString();
                    affectedBale.Name            = pbiFields[0];
                    affectedBale.PbiNumber       = pbiFields[0];
                    affectedBale.Created         = DateTime.Parse(pbiFields[1] + " " + pbiFields[2]).ToUniversalTime();
                    affectedBale.Created         = affectedBale.Created.AddMilliseconds(lineCount);
                    affectedBale.SyncedToCloud   = false;
                    affectedBale.NetWeight       = decimal.Parse(pbiFields[3]);
                    affectedBale.WeightFromScale = affectedBale.NetWeight + 3.0M;
                    affectedBale.TareWeight      = 3.0M;
                    affectedBale.ScanNumber      = lineCount;
                    affectedBale.SyncedToCloud   = false;
                    affectedBale.NetWeight       = decimal.Parse(pbiFields[3]);
                    Console.WriteLine("CREATING PBI: " + affectedBale.PbiNumber + " " + affectedBale.Created.ToString("MM/dd/yyyy HH:mm:ss"));
                    uow.BalesRepository.Add(affectedBale);
                }
                uow.SaveChanges();
            }
            #endregion
        }
Exemplo n.º 5
0
        private static void createGinLoads()
        {
            int currentGinTagNumber = 5000;
            int bridgeLoad          = 0;

            System.Random rand = new Random(55);
            using (IUnitOfWork uow = UnitOfWorkFactory.CreateUnitOfWork())
            {
                var fields = uow.FieldRepository.GetAll().OrderBy(x => x.Created).ToList();

                foreach (var field in fields)
                {
                    Console.WriteLine("CREATING LOADS FOR FIELD: " + field.Name);
                    var modules = uow.ModuleRepository.FindMatching(m => m.FieldId == field.Id, new string[] { "ModuleHistory" }).ToArray();

                    int           loadModuleCount = 0;
                    GinLoadEntity affectedGinLoad = null;
                    for (var i = 0; i < modules.Count(); i++)
                    {
                        if (loadModuleCount == 0 || loadModuleCount == 4)
                        {
                            loadModuleCount = 0;
                            bridgeLoad++;
                            currentGinTagNumber++;
                            Console.WriteLine("CREATING LOAD: " + currentGinTagNumber.ToString());
                            //break modules up into loads of 4
                            affectedGinLoad               = new GinLoadEntity();
                            affectedGinLoad.Created       = DateTime.UtcNow;
                            affectedGinLoad.SyncedToCloud = false;

                            affectedGinLoad.Name             = currentGinTagNumber.ToString();
                            affectedGinLoad.GinTagLoadNumber = currentGinTagNumber.ToString();

                            affectedGinLoad.NetWeight    = Convert.ToDecimal(rand.Next(18000, 20300));
                            affectedGinLoad.GrossWeight  = affectedGinLoad.NetWeight + 8200;
                            affectedGinLoad.SplitWeight1 = affectedGinLoad.NetWeight;
                            affectedGinLoad.SplitWeight2 = 0.00M;

                            affectedGinLoad.ScaleBridgeId         = "BRIDGE1";
                            affectedGinLoad.ScaleBridgeLoadNumber = bridgeLoad;
                            affectedGinLoad.Source        = InputSource.GIN;
                            affectedGinLoad.SyncedToCloud = false;

                            affectedGinLoad.TruckID = "TRUCK1";

                            affectedGinLoad.YardLocation = "SOMEWHERE";
                            affectedGinLoad.SubmittedBy  = "TEST HARNESS";

                            //add client/farm/field information
                            affectedGinLoad.FieldId = field.Id;
                            uow.GinLoadRepository.Save(affectedGinLoad);
                            uow.SaveChanges();
                        }


                        var module = modules[i];
                        module.Updated = DateTime.UtcNow;

                        //update module with scan information and link to load
                        module.TruckID      = affectedGinLoad.TruckID;
                        module.LastBridgeId = "BRIDGE1";
                        module.GinLoadId    = affectedGinLoad.Id;

                        if (string.IsNullOrEmpty(module.FirstBridgeId))
                        {
                            module.FirstBridgeId = "BRIDGE1";
                        }

                        module.GinTagLoadNumber = affectedGinLoad.GinTagLoadNumber;
                        module.ClassingModuleId = "";
                        module.ModuleStatus     = ModuleStatus.AT_GIN;

                        ModuleHistoryEntity historyItem = new ModuleHistoryEntity();
                        historyItem.Id               = Guid.NewGuid().ToString();
                        historyItem.Created          = DateTime.UtcNow;//moduleScan.ScanTime.HasValue ? moduleScan.ScanTime.Value : DateTime.UtcNow;
                        historyItem.Driver           = "";
                        historyItem.TruckID          = "TRUCK1";
                        historyItem.BridgeId         = "BRIDGE1";
                        historyItem.BridgeLoadNumber = bridgeLoad;
                        historyItem.GinTagLoadNumber = affectedGinLoad.GinTagLoadNumber;
                        historyItem.Name             = affectedGinLoad.GinTagLoadNumber;
                        historyItem.ModuleStatus     = ModuleStatus.AT_GIN;
                        historyItem.Latitude         = module.Latitude;
                        historyItem.Longitude        = module.Longitude;
                        historyItem.ModuleEventType  = ModuleEventType.BRIDGE_SCAN;
                        historyItem.SyncedToCloud    = false;
                        historyItem.ModuleId         = module.Id;
                        module.ModuleHistory.Add(historyItem);
                        uow.ModuleRepository.Save(module);
                        // uow.SaveChanges();

                        loadModuleCount++;
                    }
                    uow.SaveChanges();
                }
            }
        }
Exemplo n.º 6
0
        public async Task LoadForm()
        {
            //initialize client drop down
            try
            {
                using (var uow = UnitOfWorkFactory.CreateUnitOfWork())
                {
                    if (dataObj != null)
                    {
                        dataObj = uow.GinLoadRepository.GetById(dataObj.Id, "Field.Farm.Client", "Modules");
                    }

                    clientSelector.Initialize(errorProvider, true, false, (dataObj != null) ? dataObj.Field.Farm.ClientId : "");
                    farmSelector.FormErrorProvider  = errorProvider;
                    fieldSelector.FormErrorProvider = errorProvider;

                    BindingHelper.BindTruckComboByName(cboTruck, "-- Select One --", (dataObj != null) ? dataObj.TruckID : string.Empty);

                    if (dataObj != null)
                    {
                        tbBridgeId.Text         = dataObj.ScaleBridgeId;
                        tbGinTagLoadNumber.Text = dataObj.GinTagLoadNumber;
                        tbGrossWeight.Text      = dataObj.GrossWeight.ToString("0.00");
                        tbNetWeight.Text        = dataObj.NetWeight.ToString("0.00");
                        tbSplitWeight1.Text     = (dataObj.SplitWeight1.HasValue) ? dataObj.SplitWeight1.Value.ToString("0.00") : "";
                        tbSplitWeight2.Text     = (dataObj.SplitWeight2.HasValue) ? dataObj.SplitWeight2.Value.ToString("0.00") : "";

                        if (!string.IsNullOrEmpty(dataObj.SubmittedBy))
                        {
                            rdoAttendant.Checked = dataObj.SubmittedBy.ToLower() == "attendant";
                            rdoDriver.Checked    = dataObj.SubmittedBy.ToLower() == "driver";
                        }

                        tbScaleBridgeLoadNumber.Text = dataObj.ScaleBridgeLoadNumber.ToString();
                        tbPickedBy.Text       = dataObj.PickedBy;
                        tbVariety.Text        = dataObj.Variety;
                        tbTrailerNumber.Text  = dataObj.TrailerNumber;
                        tbYardLocation.Text   = dataObj.YardLocation;
                        lblModulesInLoad.Text = "";
                        foreach (var module in dataObj.Modules)
                        {
                            lblModulesInLoad.Text += module.Name + ", ";
                        }
                        lblModulesInLoad.Text = lblModulesInLoad.Text.Trim(", ".ToCharArray());
                    }
                    else
                    {
                        tbBridgeId.Text              = string.Empty;
                        tbGinTagLoadNumber.Text      = string.Empty;
                        tbGrossWeight.Text           = string.Empty;
                        tbNetWeight.Text             = string.Empty;
                        tbSplitWeight1.Text          = string.Empty;
                        tbSplitWeight2.Text          = string.Empty;
                        rdoAttendant.Checked         = true;
                        rdoDriver.Checked            = false;
                        tbScaleBridgeLoadNumber.Text = string.Empty;
                        tbPickedBy.Text              = string.Empty;
                        tbVariety.Text        = string.Empty;
                        tbTrailerNumber.Text  = string.Empty;
                        tbYardLocation.Text   = string.Empty;
                        lblModulesInLoad.Text = "--";
                        lblModulesInLoad.Text = string.Empty;
                    }
                    clearErrors();
                }
            }
            catch (Exception exc)
            {
                Logging.Logger.Log(exc);
                throw new Exception("Error occurred loading gin load form.", exc);
            }
        }
Exemplo n.º 7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            BusyMessage.Show("Saving...", this.FindForm());
            try
            {
                ValidateForm();
                if (!hasError)
                {
                    using (var uow = UnitOfWorkFactory.CreateUnitOfWork())
                    {
                        GinLoadEntity existingLoad = null;

                        if (dataObj == null)
                        {
                            existingLoad = new GinLoadEntity();
                        }
                        else
                        {
                            existingLoad = uow.GinLoadRepository.GetById(dataObj.Id, "Field.Farm.Client");
                        }

                        //ensure client, farm, and field are created
                        var client = clientSelector.GetOrCreateClientEntity();
                        var farm   = farmSelector.GetOrCreateFarmEntity(client);
                        var field  = fieldSelector.GetOrCreateFieldEntity(farm);

                        string truck = (cboTruck.SelectedIndex > 0) ? ((BaseEntity)cboTruck.SelectedItem).Name : "";

                        existingLoad.Name = tbScaleBridgeLoadNumber.Text.Trim();
                        existingLoad.ScaleBridgeLoadNumber = int.Parse(tbScaleBridgeLoadNumber.Text.Trim());
                        existingLoad.ScaleBridgeId         = tbBridgeId.Text.Trim();
                        existingLoad.GinTagLoadNumber      = tbGinTagLoadNumber.Text.Trim();
                        existingLoad.GrossWeight           = decimal.Parse(tbGrossWeight.Text.Trim());
                        existingLoad.NetWeight             = decimal.Parse(tbNetWeight.Text.Trim());

                        if (!string.IsNullOrWhiteSpace(tbSplitWeight1.Text))
                        {
                            existingLoad.SplitWeight1 = decimal.Parse(tbSplitWeight1.Text.Trim());
                        }
                        else
                        {
                            existingLoad.SplitWeight1 = null;
                        }

                        if (!string.IsNullOrWhiteSpace(tbSplitWeight2.Text))
                        {
                            existingLoad.SplitWeight2 = decimal.Parse(tbSplitWeight2.Text.Trim());
                        }
                        else
                        {
                            existingLoad.SplitWeight2 = null;
                        }

                        if (rdoAttendant.Checked)
                        {
                            existingLoad.SubmittedBy = "attendant";
                        }
                        else
                        {
                            existingLoad.SubmittedBy = "driver";
                        }

                        existingLoad.TruckID       = truck;
                        existingLoad.YardLocation  = tbYardLocation.Text;
                        existingLoad.PickedBy      = tbPickedBy.Text;
                        existingLoad.Variety       = tbVariety.Text;
                        existingLoad.TrailerNumber = tbTrailerNumber.Text;
                        existingLoad.ScaleBridgeId = tbBridgeId.Text;
                        existingLoad.FieldId       = field.Id;
                        existingLoad.SyncedToCloud = false;
                        uow.GinLoadRepository.Save(existingLoad);
                        uow.SaveChanges();

                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
                else
                {
                    this.Activate();
                }
            }
            catch (Exception exc)
            {
                Logging.Logger.Log(exc);
                MessageBox.Show("An error occurred trying to save module.");
            }
            finally
            {
                BusyMessage.Close();
            }
        }