Exemplo n.º 1
0
        /// <summary>
        /// 增加一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual bool Add(StockItemEntity entity)
        {
            if (entity.ItemID <= 0)
            {
                entity.ItemID = GetNewID();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into StockItem (" +
                            "ItemID," +
                            "StockID," +
                            "ProductID," +
                            "Property," +
                            "Amount," +
                            "Price," +
                            "TableName) " +
                            "values(" +
                            "@ItemID," +
                            "@StockID," +
                            "@ProductID," +
                            "@Property," +
                            "@Amount," +
                            "@Price," +
                            "@TableName)";

            return(_DB.ExeSQLResult(strSQL, dict));
        }
Exemplo n.º 2
0
        private void BindItemEntities()
        {
            var rows       = Request.Params["rows"].Convert <int>();
            var stockItems = new List <StockItemEntity>();

            for (int i = 0; i < rows; i++)
            {
                var productId       = Request.Params["ProductId" + i].Convert <long>();
                var count           = Request.Params["Count" + i].Convert <int>();
                var storehouseId    = Request.Params["StorehouseId" + i].Convert <long>();
                var name            = Request.Params["Name" + i].Convert <string>();
                var stockItemEntity = new StockItemEntity
                {
                    Product    = Ioc.Resolve <IApplicationService, ProductEntity>().GetEntity <ProductEntity>(productId),
                    Count      = count,
                    Storehouse = Ioc.Resolve <IApplicationService, StorehouseEntity>().GetEntity <StorehouseEntity>(storehouseId),
                    Name       = name,
                };
                stockItems.Add(stockItemEntity);
            }
            if (stockItems.Count > 0)
            {
                GridView1.DataSource = stockItems;
                GridView1.DataBind();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <int> InsertAsync(StockItemEntity entity)
        {
            if (entity.ItemID <= 0)
            {
                entity.ItemID = GetNewID();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into StockItem (" +
                            "ItemID," +
                            "StockID," +
                            "ProductID," +
                            "Property," +
                            "Amount," +
                            "Price," +
                            "TableName) " +
                            "values(" +
                            "@ItemID," +
                            "@StockID," +
                            "@ProductID," +
                            "@Property," +
                            "@Amount," +
                            "@Price," +
                            "@TableName)";

            if (await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)))
            {
                return(DataConverter.CLng(entity.ItemID));
            }
            return(-1);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 生产出入库
        /// </summary>
        /// <returns></returns>
        public virtual StockEntity CreateStocks()
        {
            if (PurchaseItems == null || PurchaseItems.Count(it => it.Product != null && it.Product.Id != 0) == 0)
            {
                return(null);
            }
            var info = new StockEntity {
                Purchase = this, StockItems = new List <StockItemEntity>(), SaveType = SaveType.Add
            };

            foreach (var purchaseItem in PurchaseItems.Where(it => it.Product != null && it.Product.Id != 0))
            {
                var stockItem = new StockItemEntity
                {
                    Count      = purchaseItem.Count,
                    Stock      = info,
                    Product    = purchaseItem.Product,
                    Storehouse = Storehouse,
                    Name       = purchaseItem.Name,
                    SaveType   = SaveType.Add
                };
                info.StockItems.Add(stockItem);
            }

            return(info);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 把实体类转换成键/值对集合
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="dict"></param>
 private static void GetParameters(StockItemEntity entity, Dictionary <string, object> dict)
 {
     dict.Add("ItemID", entity.ItemID);
     dict.Add("StockID", entity.StockID);
     dict.Add("ProductID", entity.ProductID);
     dict.Add("Property", entity.Property);
     dict.Add("Amount", entity.Amount);
     dict.Add("Price", entity.Price);
     dict.Add("TableName", entity.TableName);
 }
Exemplo n.º 6
0
        /// <summary>
        /// 加载产品明细
        /// </summary>
        /// <param name="info"></param>
        protected virtual void FillStockItemsByProductIds(StockEntity info)
        {
            if (string.IsNullOrEmpty(hfProducts.Value))
            {
                return;
            }
            var stockItems = hfProducts.Value.DeserializeJson <List <Dictionary <string, object> > >();

            if (stockItems != null)
            {
                foreach (var subStockItem in stockItems)
                {
                    var values = subStockItem as Dictionary <string, object>;
                    if (values == null)
                    {
                        continue;
                    }
                    var stockItem = new StockItemEntity {
                        Stock = info, User = new UserEntity {
                            Id = Identity.Id
                        }, SaveType = SaveType.Add
                    };
                    foreach (var value in values)
                    {
                        switch (value.Key)
                        {
                        case "Id":
                            stockItem.Product = new ProductEntity {
                                Id = value.Value.Convert <long>()
                            };
                            break;

                        case "Count":
                            stockItem.Count = value.Value.Convert <int>();
                            break;

                        case "Name":
                            stockItem.Name = value.Value.ToString();
                            break;

                        case "Remark":
                            stockItem.Remark = value.Value.ToString();
                            break;

                        case "StorehouseId":
                            stockItem.Storehouse = new StorehouseEntity {
                                Id = value.Value.Convert <long>()
                            };
                            break;
                        }
                    }
                    info.StockItems.Add(stockItem);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static StockItemEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            StockItemEntity info = new StockItemEntity();

            info.ItemID    = rdr.GetInt32("ItemID");
            info.StockID   = rdr.GetInt32("StockID");
            info.ProductID = rdr.GetInt32("ProductID");
            info.Property  = rdr.GetString("Property");
            info.Amount    = rdr.GetInt32("Amount");
            info.Price     = rdr.GetDecimal("Price");
            info.TableName = rdr.GetString("TableName");
            return(info);
        }
Exemplo n.º 8
0
        protected override StockEntity FillEntity()
        {
            var stockEntity = base.FillEntity();

            stockEntity.Order = new OrderEntity {
                Id = OrderId
            };

            stockEntity.SaveType   = SaveType.Add;
            stockEntity.Type       = StockType.SalesOut;
            stockEntity.StockItems = new List <StockItemEntity>();
            foreach (GridViewRow gvr in GridView1.Rows)
            {
                if (gvr.RowType != DataControlRowType.DataRow)
                {
                    continue;
                }
                var txtCount = gvr.FindControl("txtCount") as System.Web.UI.HtmlControls.HtmlInputText;
                if (txtCount == null)
                {
                    continue;
                }
                var txtsubRemark = gvr.FindControl("txtRemark") as System.Web.UI.HtmlControls.HtmlInputText;
                if (txtsubRemark == null)
                {
                    continue;
                }
                var storehouseId = gvr.FindControl("hidStorehouseId") as System.Web.UI.HtmlControls.HtmlInputHidden;
                var productId    = gvr.FindControl("hidProductEntity") as System.Web.UI.HtmlControls.HtmlInputHidden;
                var name         = gvr.FindControl("hidName") as System.Web.UI.HtmlControls.HtmlInputHidden;
                var stockItem    = new StockItemEntity
                {
                    Stock      = stockEntity,
                    Storehouse = new StorehouseEntity {
                        Id = storehouseId.Value.Convert <long>()
                    },
                    Product = new ProductEntity {
                        Id = productId.Value.Convert <long>()
                    },
                    Name  = name.Value,
                    Count = -(Math.Abs(txtCount.Value.Convert <int>())),
                    User  = new UserEntity {
                        Id = Identity.Id
                    },
                    Remark   = txtsubRemark.Value,
                    SaveType = SaveType.Add
                };
                stockEntity.StockItems.Add(stockItem);
            }
            return(stockEntity);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <StockItemEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            StockItemEntity obj    = null;
            string          strSQL = "select top 1 * from StockItem where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Exemplo n.º 10
0
        public long AddNew(HolderSvcModel model)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                CommonService <SettingsEntity>    scs = new CommonService <SettingsEntity>(dbc);
                CommonService <StockItemEntity>   cs  = new CommonService <StockItemEntity>(dbc);
                CommonService <JournalTypeEntity> jcs = new CommonService <JournalTypeEntity>(dbc);
                CommonService <HolderEntity>      hcs = new CommonService <HolderEntity>(dbc);
                if (hcs.GetAll().SingleOrDefault(h => h.Mobile == model.Mobile) != null)
                {
                    return(-2);
                }
                StockItemEntity stockItem = cs.GetAll().Where(s => s.Id == model.StockItemId).SingleOrDefault();
                long            holderadd = jcs.GetAll().SingleOrDefault(j => j.Name == "holderadd").Id;
                if (stockItem == null)
                {
                    return(-1);
                }

                var seting = scs.GetAll().SingleOrDefault(s => s.Name == "takecashtime");

                HolderEntity entity = new HolderEntity();
                entity.Amount       = model.Amount;
                entity.BankAccount  = model.BankAccount;
                entity.BankName     = model.BankName;
                entity.Contact      = model.Mobile;
                entity.IdNumber     = model.IdNumber;
                entity.Mobile       = model.Mobile;
                entity.Name         = model.Name;
                entity.Gender       = model.Gender;
                entity.Proportion   = model.Amount / stockItem.TotalAmount;
                entity.TotalAssets  = model.Amount;
                entity.Password     = model.Password;
                entity.Copies       = model.Copies;
                entity.TakeCashTime = entity.CreateTime.AddDays(Convert.ToDouble(seting.Value));

                stockItem.HaveCopies = stockItem.HaveCopies - model.Copies;

                JournalEntity journal = new JournalEntity();
                journal.BalanceAmount = entity.TotalAssets;
                journal.InAmount      = entity.Amount;
                journal.JournalTypeId = holderadd;
                journal.Remark        = "后台添加股东";

                dbc.Holder.Add(entity);
                dbc.Journal.Add(journal);
                dbc.SaveChanges();
                return(entity.Id);
            }
        }
Exemplo n.º 11
0
 public long AddNew(string name, string description, decimal totalAmount, long totalCopies, long issueCopies)
 {
     using (MyDbContext dbc = new MyDbContext())
     {
         StockItemEntity entity = new StockItemEntity();
         entity.Name        = name;
         entity.Description = description;
         entity.TotalAmount = totalAmount;
         entity.TotalCopies = totalCopies;
         entity.IssueCopies = issueCopies;
         entity.UnitPrice   = entity.TotalAmount / entity.TotalCopies;
         dbc.StockItems.Add(entity);
         dbc.SaveChanges();
         return(entity.Id);
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// 更新一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> UpdateAsync(StockItemEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update StockItem SET " +
                            "StockID = @StockID," +
                            "ProductID = @ProductID," +
                            "Property = @Property," +
                            "Amount = @Amount," +
                            "Price = @Price," +
                            "TableName = @TableName" +
                            " WHERE " +

                            "ItemID = @ItemID";

            return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)));
        }
Exemplo n.º 13
0
 /// <summary>
 /// 填充发票
 /// </summary>
 /// <param name="info"></param>
 protected virtual void FillStockItems(StockEntity info)
 {
     info.StockItems = new List <StockItemEntity>();
     foreach (GridViewRow gvr in gvProduct.Rows)
     {
         if (gvr.RowType != DataControlRowType.DataRow)
         {
             continue;
         }
         var ckSelect = gvr.FindControl("hfId") as System.Web.UI.HtmlControls.HtmlInputHidden;
         if (ckSelect == null)
         {
             continue;
         }
         var txtsubCount    = gvr.FindControl("txtCount") as System.Web.UI.HtmlControls.HtmlInputText;
         var hfName         = gvr.FindControl("hfName") as System.Web.UI.HtmlControls.HtmlInputHidden;
         var hfStorehouseId = gvr.FindControl("hfStorehouseId") as System.Web.UI.HtmlControls.HtmlInputHidden;
         var txtsubRemark   = gvr.FindControl("txtRemark") as System.Web.UI.HtmlControls.HtmlInputHidden;
         if (hfStorehouseId == null || txtsubCount == null || txtCount == null || hfName == null || txtsubRemark == null)
         {
             continue;
         }
         var purchaseItem = new StockItemEntity
         {
             Product = new ProductEntity {
                 Id = ckSelect.Value.Convert <long>()
             },
             Count      = txtsubCount.Value.Convert <int>(),
             Name       = hfName.Value,
             Stock      = info,
             Storehouse = new StorehouseEntity {
                 Id = hfStorehouseId.Value.Convert <long>()
             },
             User = new UserEntity {
                 Id = Identity.Id
             },
             Remark   = txtsubRemark.Value,
             SaveType = SaveType.Add
         };
         info.StockItems.Add(purchaseItem);
     }
     FillStockItemsByProductIds(info);
 }
Exemplo n.º 14
0
 /// <summary>
 /// 增加或更新一条记录(异步方式)
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual async Task <bool> AddOrUpdateAsync(StockItemEntity entity, bool IsSave)
 {
     return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity));
 }
Exemplo n.º 15
0
 /// <summary>
 /// 增加或更新一条记录
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual bool AddOrUpdate(StockItemEntity entity, bool IsSave)
 {
     return(IsSave ? Add(entity) : Update(entity));
 }