public static int Insert(PurchaseOrderItem rec)
        {
            DBAccess db = new DBAccess();

            if (rec.Status <= (int)PurchaseOrderItem_StatusEnum.Create)
            {
                rec.Status = PurchaseOrderItem_StatusEnum.Active;
            }
            AddParms(ref db, rec);
            SqlParameter objParam = new SqlParameter("@ID", 0);

            objParam.Direction = ParameterDirection.Output;
            db.Parameters.Add(objParam);

            int retval = db.ExecuteNonQuery(_SQLInsert);

            if (retval == 1)
            {
                int res = -1;
                res = Funktioner.ToInteger(objParam.Value);
                AddLog(Status: "PurchaseOrderItem", Logtext: string.Format("Create PurchaseOrderItem: ID:{0}", rec.ID), Metode: "Insert");
                return(res);
            }
            else
            {
                AddLog(Status: "PurchaseOrderItem", Logtext: string.Format("Failure to create PurchaseOrderItem:"), logtype: LogTypeEnum.Error, Metode: "Insert");
                return(-1);
            }
        }
        public static string Tags(string tekst, RescueTekniq.BOL.PurchaseOrderItem item)
        {
            string        res = "";
            StringBuilder sb  = new StringBuilder();

            sb.Append(tekst);

            sb.Replace("[PURCHASEORDER.LINE.POS]", System.Convert.ToString(item.Pos));
            sb.Replace("[PURCHASEORDER.LINE.STATUS]", item.StatusText);

            sb.Replace("[PURCHASEORDER.LINE.ITEMNAME]", item.ItemName);
            sb.Replace("[PURCHASEORDER.LINE.ITEMNO]", item.ItemNo);

            sb.Replace("[PURCHASEORDER.LINE.QUANTITY]", System.Convert.ToString(item.Quantity));

            sb.Replace("[PURCHASEORDER.LINE.ITEMPRICE]", item.ItemPrice.ToString("C"));

            sb.Replace("[PURCHASEORDER.LINE.LINETOTAL]", item.LinePrice.ToString("C"));

            //.Replace("[PURCHASEORDER.LINE.VAT]", item.VAT.ToString)
            //.Replace("[PURCHASEORDER.LINE.FREIGHT]", item.Freight.ToString("C"))

            //.Replace("[PURCHASEORDER.LINE.LINETEXT]", item.LineText)
            //.Replace("[PURCHASEORDER.LINE.SERIALNO]", item.SerialNo)

            res = sb.ToString();
            res = item.Item.Tags(res);

            return(res);
        }
        public static System.Collections.Generic.List <PurchaseOrderItem> GetPurchaseOrderItemList(int PurchaseOrderID)
        {
            System.Collections.Generic.List <PurchaseOrderItem> result = new System.Collections.Generic.List <PurchaseOrderItem>();
            PurchaseOrderItem rec = default(PurchaseOrderItem);

            DBAccess db = new DBAccess();

            db.AddInt("PurchaseOrderID", PurchaseOrderID);

            SqlDataReader dr = default(SqlDataReader);

            try
            {
                dr = (System.Data.SqlClient.SqlDataReader)(db.ExecuteReader(_SQLSelectAll));  //CType(db.ExecuteReader(_SQLSelectAllID), SqlDataReader)
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        rec = new PurchaseOrderItem();
                        Populate(dr, rec);
                        result.Add(rec); //(PurchaseOrderItem.GetPurchaseOrderItem(dr.DBtoInt("ID")))
                    }
                }
                dr.Close();
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            return(result);
        }
        public static int Save(PurchaseOrderItem rec)
        {
            int retval = 0;

            if (rec.ID > 0)
            {
                retval = Update(rec);
            }
            else
            {
                retval = Insert(rec);
            }
            return(retval);
        }
        public static int Update(PurchaseOrderItem rec)
        {
            DBAccess db = new DBAccess();

            db.AddInt("ID", rec.ID);
            AddParms(ref db, rec);

            int retval = 0;

            //Try
            retval = db.ExecuteNonQuery(_SQLUpdate);
            //Catch
            //End Try
            AddLog(Status: "PurchaseOrderItem", Logtext: string.Format("Update PurchaseOrderItem: ID:{0}", rec.ID), Metode: "Update");
            return(retval);
        }
        public static PurchaseOrderItem GetPurchaseOrderItem(int ID)
        {
            DBAccess          db  = new DBAccess();
            PurchaseOrderItem rec = new PurchaseOrderItem();

            db.AddInt("ID", ID);
            SqlDataReader dr = (SqlDataReader)(db.ExecuteReader(_SQLSelectOne));  //CType(db.ExecuteReader(_SQLSelectOne), SqlDataReader)

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Populate(dr, rec);
                }
            }
            if (!dr.IsClosed)
            {
                dr.Close();
            }
            return(rec);
        }
        private static void Populate(SqlDataReader dr, PurchaseOrderItem rec)
        {
            PopulateStandard(dr, rec);
            var with_1 = rec;

            with_1.PurchaseOrderID = System.Convert.ToInt32(dr.DBtoInt("PurchaseOrderID"));
            with_1.Pos             = System.Convert.ToInt32(dr.DBtoInt("Pos"));
            with_1.Status          = (RescueTekniq.BOL.PurchaseOrderItem_StatusEnum)(dr.DBtoInt("Status"));

            with_1.ItemID           = System.Convert.ToInt32(dr.DBtoInt("ItemID"));
            with_1.ItemName         = dr.DBtoString("ItemName");
            with_1.SupplierItemID   = dr.DBtoString("SupplierItemID");
            with_1.SupplierItemName = dr.DBtoString("SupplierItemName");
            with_1.SupplierID       = System.Convert.ToInt32(dr.DBtoInt("SupplierID"));

            with_1.Quantity   = System.Convert.ToDecimal(dr.DBtoDecimal("Quantity"));
            with_1.ItemPrice  = System.Convert.ToDecimal(dr.DBtoDecimal("ItemPrice"));
            with_1._LinePrice = System.Convert.ToDecimal(dr.DBtoDecimal("LinePrice"));
            with_1._PurchaseOrder_TotalPrice = System.Convert.ToDecimal(dr.DBtoDecimal("PurchaseOrder_TotalPrice"));

            with_1.ExpectedReceiptDate = System.Convert.ToDateTime(dr.DBtoDateTime("ExpectedReceiptDate"));
            with_1.ReceiptDate         = System.Convert.ToDateTime(dr.DBtoDateTime("ReceiptDate"));
        }
        private static void AddParms(ref DBAccess db, PurchaseOrderItem rec)
        {
            var with_1 = rec;

            db.AddInt("PurchaseOrderID", with_1.PurchaseOrderID);
            db.AddInt("Pos", with_1.Pos);
            db.AddInt("Status", (System.Int32)with_1.Status);

            db.AddInt("ItemID", with_1.ItemID);
            db.AddNVarChar("ItemName", with_1.ItemName, 100);

            db.AddNVarChar("SupplierItemID", with_1.SupplierItemID, 50);
            db.AddNVarChar("SupplierItemName", with_1.SupplierItemName, 250);

            db.AddDecimal("Quantity", with_1.Quantity);
            db.AddMoney("ItemPrice", (double)with_1.ItemPrice);
            db.AddMoney("LinePrice", (double)with_1.LinePrice);

            db.AddDateTime("ExpectedReceiptDate", with_1.ExpectedReceiptDate);
            db.AddDateTime("ReceiptDate", with_1.ReceiptDate);

            AddParmsStandard(db, rec);
        }
 public static int Delete(PurchaseOrderItem rec)
 {
     return(Delete(rec.ID));
 }