Exemplo n.º 1
0
 public static DataRow AdjustRollLength
 (
     StockRollItem roll,
     double AdjustmentQty,
     string Reference,
     string Reference2,
     string Description
 )
 {
     return((DataRow)CTechCore.WaitForms.cWaitWindow.Show(AdjustRollLength, "xxxxxx", new object[] { roll, AdjustmentQty, Reference, Reference2, Description }));
 }
Exemplo n.º 2
0
        public static void AdjustRollLength(object sender, CTechCore.WaitForms.WaitWindowEventArgs e)
        {
            StockRollItem roll          = (StockRollItem)e.Arguments[0];
            double        AdjustmentQty = (double)e.Arguments[1];
            string        Reference     = (string)e.Arguments[2];
            string        Reference2    = (string)e.Arguments[3];
            string        Description   = (string)e.Arguments[4];

            try
            {
                MyApp.PastelHlpr.CreateCommonDBConnection("uid=" + MyApp.Common.Username + ";pwd=" + MyApp.Common.Password + ";Initial Catalog=" + MyApp.Common.Database + ";server=" + MyApp.Common.Server + ";Persist Security Info=True;");
                MyApp.PastelHlpr.SetLicense(MyApp.serialNumber, MyApp.AuthorizationKey);
                MyApp.PastelHlpr.CreateConnection("server=" + MyApp.Evo.Server + ";initial catalog=" + MyApp.Evo.Database + ";User ID=" + MyApp.Evo.Username + ";Password="******";Persist Security Info=True");


                Pastel.Evolution.InventoryOperation operation = AdjustmentQty < 0 ? Pastel.Evolution.InventoryOperation.Decrease : Pastel.Evolution.InventoryOperation.Increase;
                //Create a instance of the InventoryTransaction class
                Pastel.Evolution.InventoryTransaction ItemInc = new Pastel.Evolution.InventoryTransaction();
                ItemInc.TransactionCode = new Pastel.Evolution.TransactionCode(Pastel.Evolution.Module.Inventory, "ADJ");                // specify a inventory transaction type generally this will be ADJ
                ItemInc.InventoryItem   = new Pastel.Evolution.InventoryItem(roll.StockCodeID);
                ItemInc.WarehouseID     = 3;
                ItemInc.Operation       = operation;          //Select the necessary enumerator increase , decrease or cost adjustment
                ItemInc.Quantity        = Math.Abs(AdjustmentQty);
                ItemInc.Reference       = Reference;
                ItemInc.Reference2      = Reference2;
                ItemInc.Description     = Description;
                if (ItemInc.Post())
                {
                    e.Window.Message = $"Evolution adjustment successful, audit number {ItemInc.Audit}";
                    DataTable         dt    = new DataTable();
                    List <Con.Params> parms = new List <CTechCore.Con.Params>()
                    {
                        new CTechCore.Con.Params()
                        {
                            Name = "stockRollID", Value = roll.ID
                        },
                        new CTechCore.Con.Params()
                        {
                            Name = "newOnHandValue", Value = roll.OnHand + (AdjustmentQty)
                        },
                        new CTechCore.Con.Params()
                        {
                            Name = "adjustment", Value = AdjustmentQty
                        },
                        new CTechCore.Con.Params()
                        {
                            Name = "staffID", Value = MyApp.Login.User.Username
                        },
                        new CTechCore.Con.Params()
                        {
                            Name = "stkAdjDescription", Value = Description
                        },
                        new CTechCore.Con.Params()
                        {
                            Name = "originalLength", Value = roll.OnHand
                        },
                        new CTechCore.Con.Params()
                        {
                            Name = "AuditNumber", Value = ItemInc.Audit
                        },
                    };
                    MyApp.CTech.ExecSQL("EXEC sp_XR_RollLengthAdjust @stockRollID, @newOnHandValue, @adjustment, @staffID, @stkAdjDescription, @originalLength, @AuditNumber", ref dt, parms);
                    if (dt.Rows.Count > 0)
                    {
                        e.Window.Message = $"Roll {roll.ID} successfully adjusted.";
                        e.Result         = dt.Rows[0];
                    }
                    else
                    {
                        throw new Exception("Failed to adjust roll stock details");
                    }
                }
            }
            catch (Exception ex)
            {
                e.Window.ProcessFailure = true;
                e.Window.Caption        = "Error";
                e.Window.ForeColor      = System.Drawing.Color.Red;
                string msg = $"Error attempting to adjust roll ID {roll.ID}: {ex.Message}.\r\n {ex.StackTrace}";
                e.Window.Message = msg;
                if (ex.InnerException != null)
                {
                    msg += ex.InnerException.ToString();
                }
                MessageBox.Show(msg);
                MyApp.Log.WriteEntry(msg, System.Diagnostics.EventLogEntryType.Error);
                e.Window.ForeColor = System.Drawing.Color.Black;
            }
        }