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; } }
public void Process(object sender, CTechCore.WaitForms.WaitWindowEventArgs e) { 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"); Int64 poid = this.HeaderInfo.Table.AsEnumerable().FirstOrDefault().Field <Int64>("AutoIndex"); DataTable dt = new DataTable(); MyApp.CTech.ExecSQL($"SELECT * from PurchaseOrder WHERE InvDocIDX = {poid}", ref dt); Pastel.Evolution.PurchaseOrder po = new Pastel.Evolution.PurchaseOrder(poid); foreach (Pastel.Evolution.OrderDetail l in po.Detail) { DataRow dr = this.DetailInfo.Table.AsEnumerable().FirstOrDefault(r => (int)r["iStockCodeID"] == l.InventoryItemID && (double)r["QtyReceived"] > 0); if (dr != null) { l.ToProcess = (double)dr["QtyReceived"]; } } e.Window.Message = "Processing GRV"; string restult = po.ProcessStock(); //po.UserFields e.Window.Message = $"Document '{restult}' created"; List <Stock.StockRollItems.StockRollItem> rolls = new List <Stock.StockRollItems.StockRollItem>(); foreach (DataRow r in dt.Rows) { DataRow dr = this.DetailInfo.Table.AsEnumerable().FirstOrDefault(x => (string)x["Code"] == (string)r["StockCode"]); rolls.Add(new Stock.StockRollItems.StockRollItem() { ID = 0, AuditNo = po.Audit, GRVNumber = restult, PONumber = po.OrderNo, SupplierID = (int)this.HeaderInfo.Table.Rows[0]["SupplierID"], StockCodeID = (int)dr["iStockCodeID"], StockCode = (string)dr["Code"], StockDescription = (string)dr["Description_1"], DyeLot = (string)r["DyeLot"], SupplierDyeLot = (string)r["SupplierDyeLot"], Available = 'Y', Location = this.Location, OpenBal = (double)r["qty"], UnitCost = (decimal)r["UnitPriceExcl"], ItemGroup = (string)dr["stgroup"], Quantity = (double)r["qty"], }); } if (rolls.Count > 0) { e.Result = Stock.StockRollItems.Save(rolls); e.Window.Message = "Roll(s)/Items created :\r" + string.Join("\r", ((DataSet)e.Result).Tables.Cast <DataTable>().SelectMany(t => t.AsEnumerable().Select(r => "\t\t" + (int)r["StockRollID"])).ToList()); } else { throw new Exception($"Failed to create Stock Rolls for Document '{restult}'"); } } catch (Exception ex) { e.Window.ForeColor = System.Drawing.Color.Red; string msg = $"Error create GRV: {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; } }