コード例 #1
0
 private static GoodsSerialEntity NewGoodsSerial(GoodsSerialEntity goodsSerial, DateTime expiredDate, string userId)
 {
     return(new GoodsSerialEntity
     {
         SerialNo = goodsSerial.SerialNo,
         ProductId = goodsSerial.ProductId,
         DispatchedCount = goodsSerial.SplitCopies,
         HospitalId = goodsSerial.HospitalId,
         VendorId = goodsSerial.VendorId,
         NeedAudit = goodsSerial.NeedAudit,
         NeedCheck = goodsSerial.NeedCheck,
         NeedSplit = false,
         SplitCopies = 0,
         SplitUnit = string.Empty,
         SplitPackageCount = 0,
         SplitCapacity = string.Empty,
         ValidDays = 0,
         BatchNo = goodsSerial.BatchNo,
         ExpiredDate = expiredDate,
         LogisticsCode = goodsSerial.LogisticsCode,
         LogisticsContent = goodsSerial.LogisticsContent,
         IsClosed = false,
         CreatedId = userId,
         CreatedTime = DateTime.Now,
         UpdatedId = userId,
         UpdatedTime = DateTime.Now
     });
 }
コード例 #2
0
        public static GoodsSerialEntity GetByBarcode(string barcode)
        {
            var sql = @"select 
	a.id,a.serial_no,a.parent_id,a.product_id,a.dispatched_count,a.hospital_id,a.vendor_id,a.need_audit,a.need_check,a.need_split,
    a.split_copies,a.split_unit,a.valid_days,a.batch_no,a.expired_date,a.split_capacity,a.split_package_count,
	a.logistics_code,a.logistics_content,a.is_closed,a.created_id,a.created_time,a.updated_id,a.updated_time 
from goods_serial a join goods_serial_barcodes b on a.id=b.serial_id and b.out=@p_out where b.barcode=@p_barcode";

            var db  = DatabaseFactory.CreateDatabase();
            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_barcode", DbType.String, barcode);
            db.AddInParameter(cmd, "p_out", DbType.Boolean, false);

            using (var reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    var entity = new GoodsSerialEntity();
                    entity.Init(reader);

                    return(entity);
                }

                return(null);
            }
        }
コード例 #3
0
        private static DateTime GetSplitExpiredDate(GoodsSerialEntity goodsSerial)
        {
            DateTime newExpiredDate;

            if (goodsSerial.ExpiredDate.HasValue && goodsSerial.ExpiredDate.Value != DateTime.MaxValue)
            {
                if (goodsSerial.ExpiredDate > DateTime.Today)
                {
                    newExpiredDate = DateTime.Today.AddDays((double)goodsSerial.ValidDays);
                    if (newExpiredDate > goodsSerial.ExpiredDate)
                    {
                        newExpiredDate = goodsSerial.ExpiredDate.Value;
                    }
                }
                else
                {
                    newExpiredDate = goodsSerial.ExpiredDate.Value;
                }
            }
            else
            {
                newExpiredDate = DateTime.MaxValue;
            }

            return(newExpiredDate);
        }
コード例 #4
0
        private static void UpdateSerialParentCount(GoodsSerialEntity entity, Database db, DbTransaction trans)
        {
            var sql = "update goods_serial set dispatched_count=dispatched_count-@p_subserial_count where id=@p_parent_id";
            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_parent_id", DbType.String, entity.ParentId);
            db.AddInParameter(cmd, "p_subserial_count", DbType.Int64, entity.DispatchedCount);
            db.ExecuteNonQuery(cmd, trans);
        }
コード例 #5
0
        private static string CreateGoodsSerial(GoodsSerialEntity parent, ReceiveFormItemEntity formItem, IList <string> barcodes, Database db, DbTransaction trans)
        {
            var goodsSerial = GoodsSerialRepository.CreateSub(parent, barcodes, formItem.ConfirmedId, db, trans);

            GoodsSerialFormRepository.Create(new GoodsSerialFormEntity
            {
                SerialId    = goodsSerial.Id,
                FormId      = formItem.Id,
                FormKind    = FormKind.ReceiveItem,
                CreatedId   = formItem.ConfirmedId,
                CreatedTime = formItem.ConfirmedTime,
            }, db, trans);

            return(goodsSerial.Id);
        }
コード例 #6
0
        internal static void UpdateSerialInfo(GoodsSerialEntity entity, Database db, DbTransaction trans)
        {
            var sql = @"update goods_serial set 
logistics_code=@p_logistics_code,logistics_content=@p_logistics_content,
updated_id=@p_updated_id,updated_time=@p_updated_time where id=@p_id";

            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_id", DbType.String, entity.Id);
            db.AddInParameter(cmd, "p_logistics_code", DbType.String, entity.LogisticsCode);
            db.AddInParameter(cmd, "p_logistics_content", DbType.String, entity.LogisticsContent);
            db.AddInParameter(cmd, "p_updated_id", DbType.String, entity.UpdatedId);
            db.AddInParameter(cmd, "p_updated_time", DbType.DateTime, entity.UpdatedTime);

            db.ExecuteNonQuery(cmd, trans);
        }
コード例 #7
0
        private static string DispatchGoods(DispatchFormEntity form, DispatchFormItemEntity formItem, Database db, DbTransaction trans)
        {
            var orderDetail = OrderFormRepository.GetItem(form.OrderDetailId);

            var goodsSerial = new GoodsSerialEntity
            {
                ProductId         = form.ProductId,
                DispatchedCount   = formItem.Count,
                HospitalId        = form.HospitalId,
                VendorId          = form.VendorId,
                NeedAudit         = orderDetail.NeedAudit,
                NeedCheck         = orderDetail.NeedCheck,
                NeedSplit         = orderDetail.NeedSplit,
                SplitCopies       = orderDetail.SplitCopies,
                SplitUnit         = orderDetail.SplitUnit,
                SplitCapacity     = orderDetail.SplitCapacity,
                SplitPackageCount = orderDetail.SplitPackageCount,
                ValidDays         = orderDetail.ValidDays,
                BatchNo           = formItem.BatchNo,
                ExpiredDate       = formItem.ExpiredDate,
                IsClosed          = false,
                CreatedId         = form.CreatedId,
                CreatedTime       = DateTime.Now,
                UpdatedId         = form.CreatedId,
                UpdatedTime       = DateTime.Now
            };

            GoodsSerialRepository.Create(goodsSerial, db, trans);

            GoodsSerialFormRepository.Create(new GoodsSerialFormEntity
            {
                SerialId    = goodsSerial.Id,
                FormId      = form.Id,
                FormKind    = FormKind.DispatchItem,
                CreatedId   = form.CreatedId,
                CreatedTime = DateTime.Now,
            }, new GoodsSerialFormEntity
            {
                SerialId    = goodsSerial.Id,
                FormId      = form.OrderDetailId,
                FormKind    = FormKind.OrderDetail,
                CreatedId   = form.CreatedId,
                CreatedTime = DateTime.Now,
            }, db, trans);

            return(goodsSerial.Id);
        }
コード例 #8
0
        public static IList <string> Create(GoodsSerialEntity entity, Database db, DbTransaction trans)
        {
            var sql = @"insert into goods_serial(
id,serial_no,product_id,dispatched_count,batch_no,expired_date,
need_audit,need_check,need_split,split_copies,split_unit,split_capacity,split_package_count,valid_days,
hospital_id,vendor_id,is_closed,created_id,created_time,updated_id,updated_time)
values(
    @p_id,@p_serial_no,@p_product_id,@p_dispatched_count,@p_batch_no,@p_expired_date,
    @p_need_audit,@p_need_check,@p_need_split,@p_split_copies,@p_split_unit,@p_split_capacity,@p_split_package_count,@p_valid_days,
    @p_hospital_id,@p_vendor_id,@p_is_closed,@p_created_id,@p_created_time,@p_updated_id,@p_updated_time)";

            entity.Id       = Guid.NewGuid().ToString();
            entity.SerialNo = FormatSerialNo(IdentityCreatorRepository.Get(GetSerialKey(), 1));

            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_id", DbType.String, entity.Id);
            db.AddInParameter(cmd, "p_serial_no", DbType.String, entity.SerialNo);
            db.AddInParameter(cmd, "p_product_id", DbType.String, entity.ProductId);
            db.AddInParameter(cmd, "p_dispatched_count", DbType.Int64, entity.DispatchedCount);
            db.AddInParameter(cmd, "p_hospital_id", DbType.String, entity.HospitalId);
            db.AddInParameter(cmd, "p_vendor_id", DbType.String, entity.VendorId);
            db.AddInParameter(cmd, "p_batch_no", DbType.String, entity.BatchNo);
            db.AddInParameter(cmd, "p_expired_date", DbType.DateTime, entity.ExpiredDate);

            db.AddInParameter(cmd, "p_need_audit", DbType.Boolean, entity.NeedAudit);
            db.AddInParameter(cmd, "p_need_check", DbType.Boolean, entity.NeedCheck);
            db.AddInParameter(cmd, "p_need_split", DbType.Boolean, entity.NeedSplit);
            db.AddInParameter(cmd, "p_split_copies", DbType.Int32, entity.SplitCopies);
            db.AddInParameter(cmd, "p_split_unit", DbType.String, entity.SplitUnit);
            db.AddInParameter(cmd, "p_split_capacity", DbType.String, entity.SplitCapacity);
            db.AddInParameter(cmd, "p_split_package_count", DbType.Int32, entity.SplitPackageCount);
            db.AddInParameter(cmd, "p_valid_days", DbType.Decimal, entity.ValidDays);

            db.AddInParameter(cmd, "p_is_closed", DbType.Boolean, entity.IsClosed);
            db.AddInParameter(cmd, "p_created_id", DbType.String, entity.CreatedId);
            db.AddInParameter(cmd, "p_created_time", DbType.DateTime, entity.CreatedTime);
            db.AddInParameter(cmd, "p_updated_id", DbType.String, entity.UpdatedId);
            db.AddInParameter(cmd, "p_updated_time", DbType.DateTime, entity.UpdatedTime);

            db.ExecuteNonQuery(cmd, trans);

            return(CreateSerialBarcodes(entity.Id, entity.DispatchedCount, db, trans));
        }
コード例 #9
0
        public static GoodsSerialEntity Get(string serialId, Database db, DbTransaction trans)
        {
            var sql = string.Format("select {0} from goods_serial where id=@p_id", COLUMNS);

            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_id", DbType.String, serialId);

            using (var reader = db.ExecuteReader(cmd, trans))
            {
                if (reader.Read())
                {
                    var entity = new GoodsSerialEntity();
                    entity.Init(reader);

                    return(entity);
                }
            }

            return(null);
        }
コード例 #10
0
        public static IList <GoodsSerialEntity> GetSplitSerials(IList <string> serialIds)
        {
            var list = new List <GoodsSerialEntity>();

            if (serialIds == null || serialIds.Count == 0)
            {
                return(list);
            }

            IList <string> names;
            string         namesSql;

            StringHelper.GenerInParameters("p_id", serialIds.Count, out names, out namesSql);

            var sql = string.Format("select {0} from goods_serial where id in ({1}) and need_split=@p_need_split", COLUMNS, namesSql);

            var db  = DatabaseFactory.CreateDatabase();
            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_need_split", DbType.Boolean, true);
            for (var i = 0; i < serialIds.Count; i++)
            {
                db.AddInParameter(cmd, names[i], DbType.String, serialIds[i]);
            }

            using (var reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    var entity = new GoodsSerialEntity();
                    entity.Init(reader);

                    list.Add(entity);
                }
            }

            return(list);
        }
コード例 #11
0
        private static IList <GoodsSerialEntity> GetSubSerials(string parentId)
        {
            var sql = string.Format("select {0} from goods_serial where parent_id=@p_parent_id", COLUMNS);

            var db  = DatabaseFactory.CreateDatabase();
            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_parent_id", DbType.String, parentId);

            var list = new List <GoodsSerialEntity>();

            using (var reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    var entity = new GoodsSerialEntity();
                    entity.Init(reader);

                    list.Add(entity);
                }
            }

            return(list);
        }
コード例 #12
0
        public static GoodsSerialEntity CreateSub(GoodsSerialEntity parent, IList <string> barcodes, string userId, Database db, DbTransaction trans)
        {
            var entity = new GoodsSerialEntity
            {
                Id                = Guid.NewGuid().ToString(),
                SerialNo          = parent.SerialNo,
                ParentId          = parent.Id,
                ProductId         = parent.ProductId,
                DispatchedCount   = barcodes.Count,
                HospitalId        = parent.HospitalId,
                VendorId          = parent.VendorId,
                NeedAudit         = parent.NeedAudit,
                NeedCheck         = parent.NeedCheck,
                NeedSplit         = parent.NeedSplit,
                SplitCopies       = parent.SplitCopies,
                SplitUnit         = parent.SplitUnit,
                SplitCapacity     = parent.SplitCapacity,
                SplitPackageCount = parent.SplitPackageCount,
                ValidDays         = parent.ValidDays,
                IsClosed          = parent.IsClosed,
                BatchNo           = parent.BatchNo,
                ExpiredDate       = parent.ExpiredDate,
                LogisticsCode     = parent.LogisticsCode,
                LogisticsContent  = parent.LogisticsContent,
                CreatedId         = userId,
                CreatedTime       = DateTime.Now,
                UpdatedId         = userId,
                UpdatedTime       = DateTime.Now
            };

            var sql = @"insert into goods_serial(
    id,serial_no,parent_id,product_id,dispatched_count,hospital_id,vendor_id,
    batch_no,expired_date,logistics_code,logistics_content,
    need_audit,need_check,need_split,split_copies,split_unit,split_capacity,split_package_count,valid_days,
    is_closed,created_id,created_time,updated_id,updated_time
)
values(
    @p_id,@p_serial_no,@p_parent_id,@p_product_id,@p_dispatched_count,@p_hospital_id,@p_vendor_id,
    @p_batch_no,@p_expired_date,@p_logistics_code,@p_logistics_content,
    @p_need_audit,@p_need_check,@p_need_split,@p_split_copies,@p_split_unit,@p_split_capacity,@p_split_package_count,@p_valid_days,
    @p_is_closed,@p_created_id,@p_created_time,@p_updated_id,@p_updated_time
)";

            var cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "p_id", DbType.String, entity.Id);
            db.AddInParameter(cmd, "p_serial_no", DbType.String, entity.SerialNo);
            db.AddInParameter(cmd, "p_parent_id", DbType.String, entity.ParentId);
            db.AddInParameter(cmd, "p_product_id", DbType.String, entity.ProductId);
            db.AddInParameter(cmd, "p_dispatched_count", DbType.Int64, entity.DispatchedCount);
            db.AddInParameter(cmd, "p_hospital_id", DbType.String, entity.HospitalId);
            db.AddInParameter(cmd, "p_vendor_id", DbType.String, entity.VendorId);
            db.AddInParameter(cmd, "p_batch_no", DbType.String, entity.BatchNo);
            db.AddInParameter(cmd, "p_expired_date", DbType.DateTime, entity.ExpiredDate);
            db.AddInParameter(cmd, "p_logistics_code", DbType.String, entity.LogisticsCode);
            db.AddInParameter(cmd, "p_logistics_content", DbType.String, entity.LogisticsContent);

            db.AddInParameter(cmd, "p_need_audit", DbType.Boolean, entity.NeedAudit);
            db.AddInParameter(cmd, "p_need_check", DbType.Boolean, entity.NeedCheck);
            db.AddInParameter(cmd, "p_need_split", DbType.Boolean, entity.NeedSplit);
            db.AddInParameter(cmd, "p_split_copies", DbType.Int32, entity.SplitCopies);
            db.AddInParameter(cmd, "p_split_unit", DbType.String, entity.SplitUnit);
            db.AddInParameter(cmd, "p_split_capacity", DbType.String, entity.SplitCapacity);
            db.AddInParameter(cmd, "p_split_package_count", DbType.Int32, entity.SplitPackageCount);
            db.AddInParameter(cmd, "p_valid_days", DbType.Decimal, entity.ValidDays);

            db.AddInParameter(cmd, "p_is_closed", DbType.Boolean, entity.IsClosed);
            db.AddInParameter(cmd, "p_created_id", DbType.String, entity.CreatedId);
            db.AddInParameter(cmd, "p_created_time", DbType.DateTime, entity.CreatedTime);
            db.AddInParameter(cmd, "p_updated_id", DbType.String, entity.UpdatedId);
            db.AddInParameter(cmd, "p_updated_time", DbType.DateTime, entity.UpdatedTime);

            db.ExecuteNonQuery(cmd, trans);

            UpdateSerialParentCount(entity, db, trans);

            UpdateSerialBarcodes(entity.Id, entity.ParentId, barcodes, db, trans);



            return(entity);
        }
コード例 #13
0
        public static IList <GoodsEntity> Split(GoodsEntity goods, GoodsSerialEntity goodsSerial, string userId)
        {
            var expiredDate     = GetSplitExpiredDate(goodsSerial);
            var product         = ProductRepository.Get(goods.ProductId);
            var hospitalProduct = HospitalProductRepository.GetOneProduct(goods.ProductId, goods.HospitalId);

            var list = new List <GoodsEntity>();

            var db = DatabaseFactory.CreateDatabase();

            using (var conn = db.CreateConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        if (UpdateSplittingUser(goods.Id, userId, db, trans))
                        {
                            var newSerial = NewGoodsSerial(goodsSerial, expiredDate, userId);
                            var barcodes  = GoodsSerialRepository.Create(newSerial, db, trans);

                            var name = !string.IsNullOrEmpty(goods.Name) ? goods.Name : hospitalProduct.Alias;
                            if (string.IsNullOrEmpty(name))
                            {
                                name = product.Name;
                            }

                            if (string.IsNullOrEmpty(hospitalProduct.SplitCapacity))
                            {
                                name += "(" + hospitalProduct.SplitCopies + "-{0})";
                            }
                            else
                            {
                                name += "(" + hospitalProduct.MiniSplitNumber + "*" + hospitalProduct.SplitCapacity + hospitalProduct.SplitUnit + "," + hospitalProduct.SplitCopies + "-{0})";
                            }

                            var index = 0;
                            foreach (var barcode in barcodes)
                            {
                                index++;

                                var newGoods = new GoodsEntity
                                {
                                    Name            = string.Format(name, index),
                                    Barcode         = barcode,
                                    SerialId        = newSerial.Id,
                                    ParentId        = goods.Id,
                                    HospitalId      = goods.HospitalId,
                                    VendorId        = goods.VendorId,
                                    ProductId       = goods.ProductId,
                                    BatchNo         = goods.BatchNo,
                                    ExpiredDate     = expiredDate,
                                    StoreroomId     = goods.StoreroomId,
                                    PackageCapacity = goodsSerial.SplitCapacity,
                                    PackageCount    = goodsSerial.SplitPackageCount,
                                    MeasuringUnit   = goodsSerial.SplitUnit,
                                    Status          = GoodsStatus.Usable,
                                    GrantedCount    = 0,
                                    SplitUserId     = userId,
                                    SplitDate       = DateTime.Now,
                                    CreatedId       = userId,
                                    CreatedTime     = DateTime.Now,
                                    UpdatedId       = userId,
                                    UpdatedTime     = DateTime.Now
                                };

                                Create(newGoods, db, trans);

                                list.Add(newGoods);
                            }

                            AdjustInventory(goods, newSerial.Id, barcodes.Count, goodsSerial.SplitPackageCount, userId, db, trans);
                        }

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }

            return(list);
        }
コード例 #14
0
 public IList <GoodsEntity> Split(GoodsEntity goods, GoodsSerialEntity goodsSerial, string userId)
 {
     return(GoodsRepsitory.Split(goods, goodsSerial, userId));
 }