예제 #1
0
        public Entity SaveEntityByOperator(Entity entity)
        {
            string strCrateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string msg          = "";

            try
            {
                this._Dal.BeginTransaction();

                UniqueDal unique = new UniqueDal(this._Dal.SqlTransaction);
                entity.Add(new SimpleProperty("Log", typeof(string)), "{\"Date\":\"" + strCrateDate + "\",\"People\":\"" + entity.GetValue("Operator").ToString() + "\"}");

                int affectedRows;
                /* 新增 */
                if (entity.GetValue("Unique").TryInt32() == 0)
                {
                    RfidCardBll cardStateBll = new RfidCardBll(this._Dal.SqlTransaction);
                    object      cardNumber   = entity.GetValue("CardNumber");
                    bool        hasUseRecord = CheckForSaveEntityInsert(cardNumber, cardStateBll);

                    int newUnique = unique.GetValueByName(this._Dal.Table);
                    entity.SetValue("Unique", newUnique);
                    entity.Add(new SimpleProperty("BarrierID", typeof(int)), null);
                    entity.Add(new SimpleProperty("ArriveDate", typeof(DateTime)), strCrateDate);
                    entity.Add(new SimpleProperty("State", typeof(int)), StateEnum.Default);
                    entity.Add(new SimpleProperty("Version", typeof(int)), 1);

                    affectedRows = this._Dal.InsertEntity(entity);
                    if (hasUseRecord)
                    {
                        affectedRows = cardStateBll.UpdateState(cardNumber.ToString(), (int)CardType.Green, (int)CardState.Door, newUnique, (int)CardComeFrom.Factry);
                    }
                    else
                    {
                        affectedRows = cardStateBll.Insert(cardNumber.ToString(), (int)CardType.Green, (int)CardState.Door, newUnique, (int)CardComeFrom.Factry);
                    }

                    msg = "发卡成功";
                }
                // 修改
                else
                {
                    CheckForSaveEntityUpdate(entity.GetValue("Unique"));

                    affectedRows = this._Dal.UpdateEntityByUniqueWithOperator(entity);

                    msg = "修改成功";
                }

                this._Dal.CommitTransaction();

                return(Helper.GetEntity(true, msg, entity.GetValue("Unique").ToString()));
            }
            catch (Exception exception)
            {
                this._Dal.RollbackTransaction();

                return(Helper.GetEntity(false, exception.Message));
            }
        }
예제 #2
0
        public Entity SaveEntityByOperator(Entity entity, string greenCardNumber)
        {
            string strCrateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string msg          = "";
            string CtrlType     = "NEW";

            try
            {
                if (entity.GetValue("FullVolume") != null && entity.GetValue("FullVolume").ToString().Trim() == "")
                {
                    entity.SetValue("FullVolume", null);
                }
                entity.Add(new SimpleProperty("Log", typeof(string)), "{\"Date\":\"" + strCrateDate + "\",\"People\":\"" + entity.GetValue("Operator").ToString() + "\"}");

                this._Dal.BeginTransaction();

                UniqueDal unique = new UniqueDal(this._Dal.SqlTransaction);

                int affectedRows;
                /* 新增 */
                if (entity.GetValue("Unique").TryInt32() == 0)
                {
                    object      woodID       = entity.GetValue("WoodID");
                    object      cardNumber   = entity.GetValue("CardNumber");
                    RfidCardBll cardStateBll = new RfidCardBll(this._Dal.SqlTransaction);
                    bool        hasUseRecord = CheckForSaveEntityInsert(woodID, cardNumber, cardStateBll);

                    entity.SetValue("Unique", unique.GetValueByName(this._Dal.Table));
                    entity.Add(new SimpleProperty("WeighTime", typeof(DateTime)), strCrateDate);
                    entity.Add(new SimpleProperty("Printed", typeof(bool)), 0);
                    entity.Add(new SimpleProperty("State", typeof(int)), StateEnum.Default);
                    entity.Add(new SimpleProperty("Version", typeof(int)), 1);

                    affectedRows = this._Dal.InsertEntity(entity);
                    affectedRows = cardStateBll.UpdateState(greenCardNumber, (int)CardType.Green, (int)CardState.Balance);
                    if (hasUseRecord)
                    {
                        affectedRows = cardStateBll.UpdateState(cardNumber.ToString(), (int)CardType.Red, (int)CardState.Balance, woodID.ToInt32());
                    }
                    else
                    {
                        affectedRows = cardStateBll.Insert(cardNumber.ToString(), (int)CardType.Red, (int)CardState.Balance, woodID.ToInt32(), (int)CardComeFrom.Weighbridge);
                    }

                    msg = "添加记录成功#" + strCrateDate;
                }
                /* 修改 */
                else
                {
                    CheckForSaveEntityUpdate(entity.GetValue("WoodID"));

                    affectedRows = this._Dal.UpdateEntityByUniqueWithOperator(entity);

                    msg = "修改记录成功";

                    CtrlType = "EDIT";
                }

                this._Dal.CommitTransaction();

                SyncFullVolumeData(entity, CtrlType);

                return(Helper.GetEntity(true, msg, entity.GetValue("Unique").ToString()));
            }
            catch (Exception exception)
            {
                this._Dal.RollbackTransaction();

                return(Helper.GetEntity(false, exception.Message));
            }
        }