Ejemplo n.º 1
0
        //SOAP v1.2, and binding is wsHttpBindin
        private bool Test_validate(Sol_Shipment sol_Shipment, Sol_Shipment_Sp sol_Shipment_Sp)
        {
            if (String.IsNullOrEmpty(Main.Sol_ControlInfo.ABCRCUserName))
            {
                MessageBox.Show("Please go to Settings -> ABCRC and add User Name and Password", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            if (checkBoxViewERBill.Checked)
            {
                f1 = new eRBill_CheckList_ListView();
            }

            //https://abcrcerbill.com/WcfAbcrcService/ //former: https://abcrcerbill.com/WsHttpsAbcrcService.svc


            WsHttpsAbcrcServiceClient client = new WsHttpsAbcrcServiceClient(); //"configName", "https://abcrcerbill.com/WsHttpsAbcrcService.svc");

            client.ClientCredentials.UserName.UserName = Main.Sol_ControlInfo.ABCRCUserName;
            client.ClientCredentials.UserName.Password = Main.Sol_ControlInfo.ABCRCPassword;

            int    intNumber    = 0;
            string strValue     = String.Empty;
            string vendorId     = String.Empty;
            string tagNumber    = String.Empty;
            string productCode  = String.Empty;
            int    iProductCode = 0;
            string quantity     = String.Empty;

            try
            {
                AbcrcERBill eRBill = new AbcrcERBill();

                strValue = sol_Shipment.RBillNumber;
                vendorId = string.Format("{0:d4}", Main.Sol_ControlInfo.VendorID);
                //parse it
                if (sol_Shipment.RBillNumber.Length < 7)
                {
                    Int32.TryParse(sol_Shipment.RBillNumber, out intNumber);
                    strValue = vendorId + string.Format("{0:d6}", intNumber);
                }
                eRBill.RBillNumber = strValue;

                ////temporaly change for testing
                //vendorId = "0000";

                eRBill.CarrierCrisID = sol_Shipment.CarrierID;
                eRBill.PlantCrisID   = sol_Shipment.PlantID;
                eRBill.TrailerNumber = sol_Shipment.TrailerNumber;
                eRBill.ProBillNumber = sol_Shipment.ProBillNumber;
                eRBill.ShippedDate   = sol_Shipment.ShippedDate;
                eRBill.SealNumber    = sol_Shipment.SealNumber;
                eRBill.LoadReference = sol_Shipment.LoadReference;

                //add used and empty bags
                AbcrcERBillBag bag;
                int            nBags = 0, nMaxBags = 0;

                AbcrcOtherShippingContainer aosc;
                int nAosc = 0, nMaxAosc = 0;

                //open product table
                Sol_Product_Sp sol_Product_Sp = new Sol_Product_Sp(Properties.Settings.Default.WsirDbConnectionString);
                Sol_Product    sol_Product;

                //open Container table
                Sol_Container_Sp sol_Container_Sp = new Sol_Container_Sp(Properties.Settings.Default.WsirDbConnectionString);
                Sol_Container    sol_Container;

                //read containers in shipment and get number of bags
                Sol_Stage_Sp     sol_Stage_Sp  = new Sol_Stage_Sp(Properties.Settings.Default.WsirDbConnectionString);
                List <Sol_Stage> sol_StageList = sol_Stage_Sp._SelectAllByShipmentID(sol_Shipment.ShipmentID);
                if (sol_StageList.Count < 1)
                {
                    MessageBox.Show("", "No containers found in shipment, cannot continue!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }
                nMaxBags = sol_StageList.Count;

                //read eRBill empty containers and get number of bags
                Sol_SupplyInventory_Sp     sol_SupplyInventory_Sp  = new Sol_SupplyInventory_Sp(Properties.Settings.Default.WsirDbConnectionString);
                List <Sol_SupplyInventory> sol_SupplyInventoryList = sol_SupplyInventory_Sp._SelectAllByShipmentID(sol_Shipment.ShipmentID);
                foreach (Sol_SupplyInventory ssi in sol_SupplyInventoryList)
                {
                    if (ssi.ProductID < 1)
                    {
                        //Empty Bags - EmptyContainer
                        nMaxAosc++;
                    }
                }

                //set max bags
                if (nMaxBags > 0)
                {
                    eRBill.Bags = new AbcrcERBillBag[nMaxBags];
                }
                if (nMaxAosc > 0)
                {
                    eRBill.AdditionalShippingContainers = new AbcrcOtherShippingContainer[nMaxAosc];
                }


                //process shipment containers
                foreach (Sol_Stage ssi in sol_StageList)
                {
                    //get ShippingContainerID for ItemTypeCrisID
                    sol_Container = sol_Container_Sp.Select(ssi.ContainerID);

                    //begin loop

                    //get productCode for ShippingContainerTypeCrisID
                    sol_Product = sol_Product_Sp.Select(ssi.ProductID);
                    Int32.TryParse(sol_Product.ProductCode, out iProductCode);
                    productCode = string.Format("{0:d4}", iProductCode);

                    bag      = new AbcrcERBillBag();
                    quantity = string.Format("{0:d5}", ssi.Quantity);

                    if (ssi.TagNumber.Length < 8)
                    {
                        Int32.TryParse(ssi.TagNumber, out intNumber);
                        tagNumber = string.Format("{0:d7}", intNumber);
                        strValue  = vendorId + productCode + quantity + tagNumber;
                    }
                    else if (ssi.TagNumber.Length == 20)
                    {
                        strValue = ssi.TagNumber;
                    }
                    else
                    {
                        string m = String.Format("Tag Number {0} has the wrong number of digits.  eR-Bill can't be processed.  Please correct the Tag Number and submit the eR-Bill again.", ssi.TagNumber);
                        MessageBox.Show("", m, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(false);
                    }

                    bag.BagTag         = strValue;                  //sol_Stage.TagNumber
                    bag.ItemTypeCrisID = iProductCode;
                    bag.ShippingContainerTypeCrisID = sol_Container.ShippingContainerTypeID;
                    bag.UnitsShipped = ssi.Quantity;     //ssi.Dozen * 12;     //KEV - this was fixed in 5.0.4.  Dozens are not used.

                    if (checkBoxViewERBill.Checked)
                    {
                        addItem(bag.BagTag, bag.ItemTypeCrisID, bag.ShippingContainerTypeCrisID, bag.UnitsShipped, ref eRBill_CheckList_ListView.listView1);
                    }


                    eRBill.Bags[nBags++] = bag;
                    //end loop
                }

                //process empty containers
                foreach (Sol_SupplyInventory ssi in sol_SupplyInventoryList)
                {
                    //bag tag ?
                    //Item Type ID
                    //Shipping Container Type ID
                    //Units Shipped

                    //get ShippingContainerID for ItemTypeCrisID
                    sol_Container = sol_Container_Sp.Select(ssi.ContainerID);

                    //}
                    if (ssi.ProductID < 1)
                    {
                        //Empty Bags - EmptyContainer
                        //empty bags
                        aosc = new AbcrcOtherShippingContainer();
                        //eRBill.AdditionalShippingContainers = new AbcrcOtherShippingContainer[1];
                        aosc.ShippingContainerTypeCrisID = sol_Container.ShippingContainerTypeID;
                        aosc.ContainersShipped           = ssi.Quantity;

                        if (checkBoxViewERBill.Checked)
                        {
                            addItem("", 0, aosc.ShippingContainerTypeCrisID, aosc.ContainersShipped, ref eRBill_CheckList_ListView.listView2);
                        }

                        eRBill.AdditionalShippingContainers[nAosc++] = aosc;
                    }
                }

                AbcrcValidationResponse response = client.ValidateErBill(eRBill);
                string c = String.Empty;

                foreach (AbcrcValidationMessage m in response.ValidationMessages)
                {
                    c = c + "\r\n" + m.ValidationMessage;
                }

                c = c + "\r\n" + response.ErrorMessage;
                if (response.Error == false && response.IsValid == true)
                {
                    //MessageBox.Show("Validation passed successful!");

                    c = String.Empty;
                    //submit
                    AbcrcSubmitResponse submitResponse = client.SubmitErBill(eRBill);
                    foreach (AbcrcValidationMessage m in submitResponse.ValidationMessages)
                    {
                        c = c + "\r\n" + m.ValidationMessage;
                    }

                    c = c + "\r\n" + submitResponse.ErrorMessage;
                    if (!(submitResponse.Error == false && submitResponse.IsValid == true))
                    {
                        //CajaDeMensaje.Show("", "Validation not passed successful, debug it!", c, CajaDeMensajeImagen.Error);
                        MessageBox.Show(c, "Even thought the erBill validation was succesfull, it was not received by the agency!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(false);
                    }
                }
                else
                {
                    //CajaDeMensaje.Show("", "Validation not passed successful, debug it!", c, CajaDeMensajeImagen.Error);
                    MessageBox.Show(c, "Validation not passed successful, debug it!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }
            }
            catch (Exception exception)
            {
                //MessageBox.Show(exception.Message);
                //CajaDeMensaje.Show("", exception.Message, exception.InnerException.Message, CajaDeMensajeImagen.Error);
                string m1 = String.Empty;
                try
                {
                    m1 = exception.InnerException.Message;
                }
                catch
                {
                    m1 = "Error when trying to create and validate eRBill's object. ";
                }

                //string m2 = exception.Message;

                MessageBox.Show(exception.Message, m1, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool CreateAdjustment(AdjustmentActionTypes adjActionTypes, int stageId, int productId)
        {
            sol_Stage = sol_Stage_Sp.Select(stageId);
            if (sol_Stage == null)
            {
                MessageBox.Show(String.Format("StageID not found ({0}) ", stageId));
                return(false);
            }

            DateTime dt = sol_Stage.Date;

            if (checkBoxDate.Checked)
            {
                dt = Main.rc.FechaActual;
            }

            Sol_Stage sol_StageAdjustment = new Sol_Stage();

            sol_StageAdjustment.ShipmentID = sol_ShipmentAdjustment.ShipmentID;
            sol_StageAdjustment.UserID     = sol_Stage.UserID;
            sol_StageAdjustment.UserName   = sol_Stage.UserName;
            //sol_StageAdjustment.Date = dt;
            sol_StageAdjustment.Date = Main.rc.FechaActual; // ; // Properties.Settings.Default.FechaActual;;

            sol_StageAdjustment.TagNumber            = sol_Stage.TagNumber + "A";
            sol_StageAdjustment.ContainerID          = sol_Stage.ContainerID;
            sol_StageAdjustment.ContainerDescription = sol_Stage.ContainerDescription;
            sol_StageAdjustment.ProductID            = sol_Stage.ProductID;
            sol_StageAdjustment.ProductName          = sol_Stage.ProductName;
            sol_StageAdjustment.Dozen    = 0; //not used anymore sol_Stage.Dozen * -1;
            sol_StageAdjustment.Quantity = sol_Stage.Quantity * -1;
            sol_StageAdjustment.Price    = sol_Stage.Price;
            sol_StageAdjustment.Remarks  = sol_Stage.Remarks;
            sol_StageAdjustment.Status   = sol_Stage.Status;

            //in case there is no default value in the db
            sol_StageAdjustment.DateClosed = DateTime.Parse("1753-01-01 12:00:00.000");

            switch (adjActionTypes)
            {
            case AdjustmentActionTypes.Return:
                //remove it
                //sol_StageAdjustment.TagNumber = sol_Stage.TagNumber;
                sol_StageAdjustment.Dozen    = sol_Stage.Dozen * -1;
                sol_StageAdjustment.Quantity = sol_Stage.Quantity * -1;
                //sol_StageAdjustment.Status = sol_Stage.Status;
                sol_Stage_Sp.Insert(sol_StageAdjustment);

                //add an adjustment to return to inventory
                sol_StageAdjustment.ShipmentID = 0;
                sol_StageAdjustment.TagNumber  = textBoxNewTagNumber.Text; //sol_Stage.TagNumber
                sol_StageAdjustment.Dozen      = 0;                        //not used anymore sol_Stage.Dozen;
                sol_StageAdjustment.Quantity   = sol_Stage.Quantity;
                sol_StageAdjustment.Status     = "I";                      //sol_Stage.Status;

                sol_Stage_Sp.Insert(sol_StageAdjustment);

                ////remove it from shipment
                //sol_Stage.ShipmentID = 0;
                //sol_Stage.TagNumber = textBoxNewTagNumber.Text;
                //sol_Stage.Status = "I";
                //sol_Stage_Sp.Update(sol_Stage);


                MessageBox.Show(
                    string.Format(
                        @"Tag Number {0} has been added to inventory. Note: This tag is in inventory and is no longer linked to the previous shipment.  Therefore, the new tag will not be removed if you delete the adjustment."
                        , textBoxNewTagNumber.Text
                        ));

                return(true);

            //break;

            case AdjustmentActionTypes.Remove:

                break;
            //case AdjustmentActionTypes.Add:
            //    break;

            case AdjustmentActionTypes.Adjust:
                //create reverse adjustment to remove original quantity
                sol_Stage_Sp.Insert(sol_StageAdjustment);

                //create adjustment with new product
                if (productId > 0)
                {
                    if (sol_Product_Sp == null)
                    {
                        sol_Product_Sp = new Sol_Product_Sp(Properties.Settings.Default.WsirDbConnectionString);
                    }
                    sol_Product = sol_Product_Sp.Select(productId);
                    sol_StageAdjustment.ProductID   = productId;
                    sol_StageAdjustment.ProductName = sol_Product.ProName;
                    //sol_StageAdjustment.Dozen = sol_Stage.Dozen;
                    //sol_StageAdjustment.Quantity = sol_Stage.Quantity;
                }

                int newQuantity = 0;
                int.TryParse(textBoxNewQuantity.Text, out newQuantity);

                sol_StageAdjustment.Quantity = newQuantity;
                sol_StageAdjustment.Dozen    = 0;   //not used anymore newQuantityOfDozens;

                break;

            //case AdjustmentActionTypes.Change:
            //    //create reverse adjustment to remove original product

            //    sol_Stage_Sp.Insert(sol_StageAdjustment);

            //    //create adjustment with new product
            //    if (sol_Product_Sp == null)
            //        sol_Product_Sp = new Sol_Product_Sp(Properties.Settings.Default.WsirDbConnectionString);
            //    sol_Product = sol_Product_Sp.Select(productId);
            //    sol_StageAdjustment.ProductID = productId;
            //    sol_StageAdjustment.ProductName = sol_Product.ProName;
            //    sol_StageAdjustment.Dozen = sol_Stage.Dozen;
            //    sol_StageAdjustment.Quantity = sol_Stage.Quantity;

            //    break;
            //case AdjustmentActionTypes.Delete:
            //    break;
            default:
                break;
            }

            sol_Stage_Sp.Insert(sol_StageAdjustment);

            return(true);
        }
Ejemplo n.º 3
0
        private void comboBoxProducts_SelectedIndexChanged(object sender, EventArgs e)
        {
            int Id = -1;

            try
            {
                Id = (int)comboBoxProducts.SelectedValue;
            }
            catch
            {
                return;
            }


            //delete row if it was new
            if (sol_Agency != null)
            {
                if (sol_Agency.AutoGenerateTagNumber)
                {
                    if (buttonClicked == "&New")
                    {
                        DeleteStagedRow();
                    }
                }
            }

            //Sol_Product sol_Product = new Sol_Product();
            if (sol_Product_Sp == null)
            {
                sol_Product_Sp = new Sol_Product_Sp(Properties.Settings.Default.WsirDbConnectionString);
            }
            sol_Product = sol_Product_Sp.Select(Id);

            comboBoxContainers.SelectedValue = sol_Product.ContainerID;


            //open table connection
            if (sol_Agency_Sp == null)
            {
                sol_Agency_Sp = new Sol_Agencie_Sp(Properties.Settings.Default.WsirDbConnectionString);
            }
            sol_Agency = sol_Agency_Sp.Select(sol_Product.AgencyID);
            //if (sol_Agency != null)
            //{
            //    Int32.TryParse(sol_Agency.VendorID, out intValue);
            //    vendorId = intValue.ToString("0000");
            //}


            if (sol_Agency.AutoGenerateTagNumber)
            {
                //add row
                if (AddStagedRow())
                {
                    textBoxTagNumber.Text     = sol_Stage.TagNumber;
                    textBoxTagNumber.ReadOnly = true;
                    comboBoxContainers.Focus();
                    comboBoxProducts.Enabled = false;
                }
                else
                {
                    buttonCancel.PerformClick();
                }
            }
            else
            {
                textBoxTagNumber.ReadOnly = false;
                //textBoxTagNumber.Focus();
            }

            //Sol_StandardDozen_Sp sol_StandardDozen_Sp = new Sol_StandardDozen_Sp(Properties.Settings.Default.WsirDbConnectionString);
            //Sol_StandardDozen sol_StandardDozen = sol_StandardDozen_Sp.Select(sol_Product.StandardDozenID);
            //textBoxDefaultDozen.Text = sol_StandardDozen.Quantity.ToString();

            textBoxQuantity.Text = sol_Product.TargetQuantity.ToString();
            textBoxDozen.Text    = SolFunctions.Quantity2Dozen(sol_Product.TargetQuantity);
        }