Beispiel #1
0
 override public void RegistInstants(params object[] instants)
 {
     if (instants.Length > 0)
     {
         this.catproductstoreContract = (CatProductStoreContract)(instants[0]);
     }
 }
Beispiel #2
0
 public static string Exchange(StoExchangeContract storeExchangeDTO, StoExchangeDetailContract storeExchangeDetailDTO, SqlTransaction tran)
 {
     try
     {
         CatProductStoreContract productStoreDTO = new CatProductStoreContract();
         string    storeCond             = "StoreID=" + storeExchangeDTO.Fromstoreid + " AND ProductId=" + storeExchangeDetailDTO.Productid;
         DataTable fromStoreProductTable = productStoreDT.GetByCond(storeCond, " OrderNum ASC");
         var       totalQuantity         = fromStoreProductTable.Compute("SUM(Quantity)", "");
         if (Converter.ToInt32(totalQuantity) < Converter.ToInt32(storeExchangeDetailDTO.Quantity))
         {
             return(string.Format("Lỗi: Số lượng trong không đủ để chuyển."));
         }
         else if (storeExchangeDTO.Fromstoreid == storeExchangeDTO.Tostoreid)
         {
             return("");
         }
         else
         {
             int tmpQuantity = 0;
             foreach (DataRow row in fromStoreProductTable.Rows)
             {
                 tmpQuantity += Converter.ToInt32(row["Quantity"]);
                 if (tmpQuantity < Converter.ToInt32(storeExchangeDetailDTO.Quantity))
                 {
                     productStoreDTO.Importcode = row["ImportCode"].ToString();
                     productStoreDTO.Importdate = row["ImportDate"].ToString();
                     productStoreDTO.Storeid    = storeExchangeDTO.Tostoreid;
                     productStoreDTO.Productid  = storeExchangeDetailDTO.Productid;
                     productStoreDTO.Inventory  = row["Quantity"].ToString();
                     productStoreDTO.Quantity   = row["Quantity"].ToString();
                     productStoreDTO.Price      = row["Price"].ToString();
                     productStoreDTO.Ordernum   = row["OrderNum"].ToString();
                     productStoreDT.Insert(productStoreDTO, tran);
                     productStoreDT.Update(new string[] { "Quantity" }, new string[] { "0" }, "ID=" + row["ID"].ToString(), tran);
                 }
                 else
                 {
                     int exchangedQuantity = Converter.ToInt32(row["Quantity"]) - (tmpQuantity - Converter.ToInt32(storeExchangeDetailDTO.Quantity));
                     int rowNewQuantity    = Converter.ToInt32(row["Quantity"]) - exchangedQuantity;
                     productStoreDTO.Importcode = row["ImportCode"].ToString();
                     productStoreDTO.Importdate = row["ImportDate"].ToString();
                     productStoreDTO.Storeid    = storeExchangeDTO.Tostoreid;
                     productStoreDTO.Productid  = storeExchangeDetailDTO.Productid;
                     productStoreDTO.Inventory  = exchangedQuantity.ToString();
                     productStoreDTO.Quantity   = exchangedQuantity.ToString();
                     productStoreDTO.Price      = row["Price"].ToString();
                     productStoreDTO.Ordernum   = row["OrderNum"].ToString();
                     productStoreDT.Insert(productStoreDTO, tran);
                     productStoreDT.Update(new string[] { "Quantity" }, new string[] { rowNewQuantity.ToString() }, "ID=" + row["ID"].ToString(), tran);
                     break;
                 }
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
     return("");
 }
Beispiel #3
0
        static void returnStore(string invoiceCode, int storeId, int productId, string quantity, SqlTransaction tran)
        {
            string    exportLogCond = "ExportCode='" + invoiceCode + "' AND ProductID=" + productId;
            DataTable dtExportLog   = productExportDT.GetByCond(exportLogCond, "", tran);

            if (dtExportLog != null && dtExportLog.Rows.Count > 0)
            {
                string    importCode      = dtExportLog.Rows[0]["ImportCode"].ToString();
                string    storeInventCond = "ImportCode='" + importCode + "' AND StoreID=" + storeId + " AND ProductID=" + productId;
                DataTable dtStoreInvent   = productStoreDT.GetByCond(storeInventCond, "", tran);
                if (dtStoreInvent != null && dtStoreInvent.Rows.Count > 0)
                {
                    productStoreDT.Update(new string[] { "Quantity" }, new string[] { "Quantity+" + quantity }, storeInventCond, tran);
                }
                else
                {
                    CatProductStoreContract productStoreDTO = new CatProductStoreContract();
                    productStoreDTO.Importcode = importCode;
                    productStoreDTO.Importdate = DateTime.Now.ToString("dd/MM/yyyy");
                    productStoreDTO.Storeid    = storeId;
                    productStoreDTO.Productid  = productId;
                    productStoreDTO.Inventory  = quantity;
                    productStoreDTO.Quantity   = quantity;
                    productStoreDTO.Price      = dtExportLog.Rows[0]["ImportPrice"].ToString();
                    productStoreDTO.Ordernum   = "0";
                    productStoreDT.Insert(productStoreDTO, tran);
                }
                productExportDT.Update(new string[] { "Quantity" }, new string[] { "Quantity-" + quantity }, exportLogCond, tran);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Insert đối tượng vào database
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public string Insert(CatProductStoreContract catproductstore, SqlTransaction tran = null)
        {
            DataTable dtResult = null;
            string    query    = string.Format(@"INSERT INTO Cat_Product_Store
                                        VALUES ({0},{1},convert(datetime,{2},103),{3},{4},{5},{6},{7})",

                                               (catproductstore.Productid != null? catproductstore.Productid.ToString() : "null").ToString(),
                                               (catproductstore.Storeid != null? catproductstore.Storeid.ToString() : "null").ToString(),
                                               (catproductstore.Importdate != null? "'" + SQLHelper.RejectInjection(catproductstore.Importdate.ToString()) + "'" : "null").ToString(),
                                               (catproductstore.Quantity.Trim() != String.Empty ? catproductstore.Quantity.ToString() : "null").ToString(),
                                               (catproductstore.Inventory.Trim() != String.Empty ? catproductstore.Inventory.ToString() : "null").ToString(),
                                               (catproductstore.Importcode.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproductstore.Importcode.ToString()) + "'" : "null").ToString(),
                                               (catproductstore.Price.Trim() != String.Empty ? catproductstore.Price.ToString() : "null").ToString(),
                                               (catproductstore.Ordernum.Trim() != String.Empty ? catproductstore.Ordernum.ToString() : "null").ToString());

            query += " ; select SCOPE_IDENTITY();";
            if (tran == null)
            {
                dtResult = DataProvider.ExecuteQuery(query);
            }
            else
            {
                dtResult = DataProvider.ExecuteQueryWithTransaction(query, tran);
            }
            if (dtResult != null && dtResult.Rows.Count > 0)
            {
                return(dtResult.Rows[0][0].ToString());
            }
            return("");
        }
Beispiel #5
0
 public static void Import(BuyImportinvoiceContract importInvoiceDTO, BuyImportinvoiceDetailContract invoiceDetailDTO, SqlTransaction tran)
 {
     try
     {
         CatProductStoreContract productStoreDTO = new CatProductStoreContract();
         productStoreDTO.Importcode = importInvoiceDTO.Code;
         productStoreDTO.Importdate = importInvoiceDTO.Createdate;
         productStoreDTO.Storeid    = importInvoiceDTO.CatStoreid;
         productStoreDTO.Productid  = invoiceDetailDTO.Productid;
         productStoreDTO.Inventory  = invoiceDetailDTO.Quantity;
         productStoreDTO.Quantity   = invoiceDetailDTO.Quantity;
         productStoreDTO.Price      = invoiceDetailDTO.Price;
         productStoreDTO.Ordernum   = invoiceDetailDTO.Importinvoiceid.ToString();
         productStoreDT.Insert(productStoreDTO, tran);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #6
0
        /// <summary>
        /// Cập nhật thông tin đối tượng
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        public string Update(CatProductStoreContract catproductstore, SqlTransaction tran = null)
        {
            string query = String.Format("UPDATE " + TableName + @" SET ProductID={0},StoreID={1},ImportDate=convert(datetime,{2},103),Quantity={3},Inventory={4},ImportCode={5},Price={6},OrderNum={7}
                            WHERE ID=" + catproductstore.Id.ToString(),
                                         (catproductstore.Productid != null? catproductstore.Productid.ToString() : "null").ToString(),
                                         (catproductstore.Storeid != null? catproductstore.Storeid.ToString() : "null").ToString(),
                                         (catproductstore.Importdate != null? "'" + SQLHelper.RejectInjection(catproductstore.Importdate.ToString()) + "'" : "null").ToString(),
                                         (catproductstore.Quantity.Trim() != String.Empty ? catproductstore.Quantity.ToString() : "null").ToString(),
                                         (catproductstore.Inventory.Trim() != String.Empty ? catproductstore.Inventory.ToString() : "null").ToString(),
                                         (catproductstore.Importcode.Trim() != String.Empty? "N'" + SQLHelper.RejectInjection(catproductstore.Importcode.ToString()) + "'" : "null").ToString(),
                                         (catproductstore.Price.Trim() != String.Empty ? catproductstore.Price.ToString() : "null").ToString(),
                                         (catproductstore.Ordernum.Trim() != String.Empty ? catproductstore.Ordernum.ToString() : "null").ToString());

            if (tran == null)
            {
                DataProvider.ExecuteNonQuery(query);
            }
            else
            {
                DataProvider.ExecuteNonQueryWithTransaction(query, tran);
            }
            return(catproductstore.Id.ToString());
        }
        public HttpResponseMessage Save(string catproductstoreJson)
        {
            string errMessage = string.Empty;

            try
            { CatProductStoreContract catproductstore = JsonConvert.DeserializeObject <CatProductStoreContract>(catproductstoreJson);
              businessRule.RegistInstants(catproductstore);
              if (catproductstore.Id == 0)
              {
                  businessRule.RegistRule("Insert");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(catproductstore)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              }
              else
              {
                  businessRule.RegistRule("Update");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(catproductstore)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              } }
            catch (Exception e)
            {
                ExceptionHandler.Log(e);
                return(Request.CreateResponse <string>(HttpStatusCode.OK, "Có lỗi xảy ra trên chương trình."));
            }
        }
Beispiel #8
0
 public CatProductStoreRule ValidateInstant(CatProductStoreContract dto)
 {
     return(this);
 }