Beispiel #1
0
        public void New(Model.Entity.DealerDevice obj)
        {
            const string sqlCommond = "Insert into DealerDevice (DealerId,DeviceId,StockTime,Purchaser,SalesTime,ReworkTime,Status,Remark,CreateTime,UpdateTime) values (@DealerId,@DeviceId,@StockTime,@Purchaser,@SalesTime,@ReworkTime,@Status,@Remark,@CreateTime,@UpdateTime)";
            var          dp         = new DbParameter[]
            {
                Data.DBHelper.CreateInDbParameter("@DealerId", DbType.Int32, obj.DealerId),
                Data.DBHelper.CreateInDbParameter("@DeviceID", DbType.Int32, obj.DeviceId),
                Data.DBHelper.CreateInDbParameter("@StockTime", DbType.DateTime, GetItemValue(obj.StockTime)),
                Data.DBHelper.CreateInDbParameter("@Purchaser", DbType.Int32, GetItemValue(obj.Purchaser)),
                Data.DBHelper.CreateInDbParameter("@SalesTime", DbType.DateTime, GetItemValue(obj.SalesTime)),
                Data.DBHelper.CreateInDbParameter("@ReworkTime", DbType.DateTime, GetItemValue(obj.ReworkTime)),
                Data.DBHelper.CreateInDbParameter("@Status", DbType.Int32, obj.Status),
                Data.DBHelper.CreateInDbParameter("@Remark", DbType.String, GetItemValue(obj.Remark)),
                Data.DBHelper.CreateInDbParameter("@CreateTime", DbType.DateTime, obj.CreateTime),
                Data.DBHelper.CreateInDbParameter("@UpdateTime", DbType.DateTime, obj.UpdateTime)
            };

            Data.DBHelper.GetInstance().ExecuteNonQuery(sqlCommond, dp);
            lock (this)
            {
                Dictionary <int, Model.Entity.DealerDevice> dictDevice;
                if (!_dictionaryByDealer.TryGetValue(obj.DealerId, out dictDevice))
                {
                    dictDevice = new Dictionary <int, Model.Entity.DealerDevice>();
                    _dictionaryByDealer.Add(obj.DealerId, dictDevice);
                }
                dictDevice.Add(obj.DeviceId, obj);
            }
        }
Beispiel #2
0
        public DealerDevice()
            : base(typeof(Model.Entity.DealerDevice))
        {
            _dictionaryByDealer = new Dictionary <int, Dictionary <int, Model.Entity.DealerDevice> >();
            const string sqlCommond = "select * from DealerDevice";
            var          ds         = Data.DBHelper.GetInstance().ExecuteAdapter(sqlCommond);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    var item = new Model.Entity.DealerDevice();
                    item.DealerId   = (int)row["DealerId"];
                    item.DeviceId   = (int)row["DeviceId"];
                    item.CreateTime = (DateTime)row["CreateTime"];
                    if (row["Purchaser"] != DBNull.Value)
                    {
                        item.Purchaser = (int)row["Purchaser"];
                    }
                    item.Status = (int)row["Status"];
                    if (row["Remark"] != DBNull.Value)
                    {
                        item.Remark = (string)row["Remark"];
                    }
                    if (row["ReworkTime"] != DBNull.Value)
                    {
                        item.ReworkTime = (DateTime)row["ReworkTime"];
                    }
                    if (row["SalesTime"] != DBNull.Value)
                    {
                        item.SalesTime = (DateTime)row["SalesTime"];
                    }
                    if (row["StockTime"] != DBNull.Value)
                    {
                        item.StockTime = (DateTime)row["StockTime"];
                    }
                    item.UpdateTime = (DateTime)row["UpdateTime"];
                    Dictionary <int, Model.Entity.DealerDevice> dictDevice;
                    if (!_dictionaryByDealer.TryGetValue(item.DealerId, out dictDevice))
                    {
                        dictDevice = new Dictionary <int, Model.Entity.DealerDevice>();
                        _dictionaryByDealer.Add(item.DealerId, dictDevice);
                    }
                    dictDevice.Add(item.DeviceId, item);
                }
            }
        }
Beispiel #3
0
        public void Update(Model.Entity.DealerDevice obj)
        {
            Dictionary <int, Model.Entity.DealerDevice> dictDevice;

            if (
                _dictionaryByDealer.TryGetValue(obj.DealerId, out dictDevice))
            {
                Model.Entity.DealerDevice item;
                if (dictDevice.TryGetValue(obj.DeviceId, out item))
                {
                    item.UpdateTime = DateTime.Now;
                    const string sqlCommond =
                        "Update DealerDevice set StockTime=@StockTime,Purchaser=@Purchaser,SalesTime=@SalesTime,ReworkTime=@ReworkTime,Status=@Status,Remark=@Remark,UpdateTime=getdate() where DealerId=@DealerId and DeviceId=@DeviceId";
                    var dp = new DbParameter[]
                    {
                        Data.DBHelper.CreateInDbParameter("@DealerId", DbType.Int32, obj.DealerId),
                        Data.DBHelper.CreateInDbParameter("@DeviceID", DbType.Int32, obj.DeviceId),
                        Data.DBHelper.CreateInDbParameter("@StockTime", DbType.DateTime, GetItemValue(obj.StockTime)),
                        Data.DBHelper.CreateInDbParameter("@Purchaser", DbType.Int32, GetItemValue(obj.Purchaser)),
                        Data.DBHelper.CreateInDbParameter("@SalesTime", DbType.DateTime, GetItemValue(obj.SalesTime)),
                        Data.DBHelper.CreateInDbParameter("@ReworkTime", DbType.DateTime, GetItemValue(obj.ReworkTime)),
                        Data.DBHelper.CreateInDbParameter("@Status", DbType.Int32, obj.Status),
                        Data.DBHelper.CreateInDbParameter("@Remark", DbType.String, GetItemValue(obj.Remark))
                    };
                    Data.DBHelper.GetInstance().ExecuteNonQuery(sqlCommond, dp);
                    if (obj != item)
                    {
                        item.StockTime  = obj.StockTime;
                        item.Purchaser  = obj.Purchaser;
                        item.SalesTime  = obj.SalesTime;
                        item.ReworkTime = obj.ReworkTime;
                        item.Status     = obj.Status;
                        item.Remark     = obj.Remark;
                    }
                }
            }
        }