/// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(WarehouseStoreME model)
 {
     StringBuilder strSql = new StringBuilder();
     strSql.Append("insert into WarehouseStore(");
     strSql.Append("houseID,houseLayerID,houseRowID,houseColumnID,name,useStatus,productID)");
     strSql.Append(" values (");
     strSql.Append("@houseID,@houseLayerID,@houseRowID,@houseColumnID,@name,@useStatus,@productID)");
     SqlParameter[] parameters = {
             new SqlParameter("@houseID", SqlDbType.Int,4),
             new SqlParameter("@houseLayerID", SqlDbType.Int,4),
             new SqlParameter("@houseRowID", SqlDbType.Int,4),
             new SqlParameter("@houseColumnID", SqlDbType.Int,4),
             new SqlParameter("@name", SqlDbType.NChar,50),
             new SqlParameter("@useStatus", SqlDbType.TinyInt,1),
             new SqlParameter("@productID", SqlDbType.NVarChar,50)};
     parameters[0].Value = model.houseID;
     parameters[1].Value = model.houseLayerID;
     parameters[2].Value = model.houseRowID;
     parameters[3].Value = model.houseColumnID;
     parameters[4].Value = model.name;
     parameters[5].Value = model.useStatus;
     parameters[6].Value = model.productID;
     int rows = _dbAssist.ExecuteSql(strSql.ToString(), parameters);
     if(rows>0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 /// <summary>
 /// 增加仓位信息
 /// </summary>
 /// <param name="cell">仓位信息记录单元</param>
 /// <returns>若已存在或不满足一致性约束则返回false</returns>
 public bool AddHousecell(WarehouseStoreME cell)
 {
     if (_dal.Exists(cell.houseID))
     {
         return false;
     }
     return _dal.Add(cell);
 }
        /// <summary>
        /// 获取所有仓位信息
        /// </summary>
        /// <returns></returns>
        public IList<WarehouseStoreME> GetAllHouseCells()
        {
            DataSet ds = _dal.GetList("  ");
            if(ds.Tables.Count> 0 && ds.Tables[0] != null)
            {
                List<WarehouseStoreME> cellList = new List<WarehouseStoreME>();

                foreach(DataRow rw in ds.Tables[0].Rows)
                {
                    WarehouseStoreME m = new WarehouseStoreME();
                    m.houseID = int.Parse(rw["houseID"].ToString());
                    m.name = rw["name"].ToString();
                    m.productID = rw["productID"].ToString();
                    m.houseLayerID = int.Parse(rw["houseLayerID"].ToString());
                    m.houseRowID = int.Parse(rw["houseRowID"].ToString());
                    m.houseColumnID = int.Parse(rw["houseColumnID"].ToString());
                    m.useStatus = int.Parse(rw["useStatus"].ToString());
                    cellList.Add(m);
                }
                return cellList;
            }
            return null;
        }
 // <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(WarehouseStoreME model)
 {
     StringBuilder strSql = new StringBuilder();
     strSql.Append("update WarehouseStore set ");
     strSql.Append("houseLayerID=@houseLayerID,");
     strSql.Append("houseRowID=@houseRowID,");
     strSql.Append("houseColumnID=@houseColumnID,");
     strSql.Append("name=@name,");
     strSql.Append("useStatus=@useStatus,");
     strSql.Append("productID=@productID");
     strSql.Append(" where houseID=@houseID ");
     SqlParameter[] parameters = {
             new SqlParameter("@houseLayerID", SqlDbType.Int,4),
             new SqlParameter("@houseRowID", SqlDbType.Int,4),
             new SqlParameter("@houseColumnID", SqlDbType.Int,4),
             new SqlParameter("@name", SqlDbType.NChar,50),
             new SqlParameter("@useStatus", SqlDbType.TinyInt,1),
             new SqlParameter("@productID", SqlDbType.NVarChar,50),
             new SqlParameter("@houseID", SqlDbType.Int,4)};
     parameters[0].Value = model.houseLayerID;
     parameters[1].Value = model.houseRowID;
     parameters[2].Value = model.houseColumnID;
     parameters[3].Value = model.name;
     parameters[4].Value = model.useStatus;
     parameters[5].Value = model.productID;
     parameters[6].Value = model.houseID;
     int rows = _dbAssist.ExecuteSql(strSql.ToString(), parameters);
     if(rows>0)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 /// <param name="houseLayerID"></param>
 /// <param name="houseRowID"></param>
 /// <param name="houseColumnID"></param>
 /// <returns></returns>
 public WarehouseStoreME GetModel(int houseLayerID, int houseRowID, int houseColumnID)
 {
     StringBuilder strSql = new StringBuilder();
     strSql.Append("select  top 1 houseID,houseLayerID,houseRowID,houseColumnID,name,useStatus,productID from WarehouseStore ");
     strSql.Append(" where houseLayerID=@houseLayerID and houseRowID=@houseRowID and houseColumnID=@houseColumnID");
     SqlParameter[] parameters = {
             new SqlParameter("@houseLayerID", SqlDbType.Int,4),
             new SqlParameter("@houseRowID", SqlDbType.Int,4),
             new SqlParameter("@houseColumnID", SqlDbType.Int,4)};
     parameters[0].Value = houseLayerID;
     parameters[1].Value = houseRowID;
     parameters[2].Value = houseColumnID;
     WarehouseStoreME model = new WarehouseStoreME();
     DataSet ds = _dbAssist.Query(strSql.ToString(), parameters);
     if (ds.Tables[0].Rows.Count > 0)
     {
         if (ds.Tables[0].Rows[0]["houseID"] != null && ds.Tables[0].Rows[0]["houseID"].ToString() != "")
         {
             model.houseID = int.Parse(ds.Tables[0].Rows[0]["houseID"].ToString());
         }
         if (ds.Tables[0].Rows[0]["houseLayerID"] != null && ds.Tables[0].Rows[0]["houseLayerID"].ToString() != "")
         {
             model.houseLayerID = int.Parse(ds.Tables[0].Rows[0]["houseLayerID"].ToString());
         }
         if (ds.Tables[0].Rows[0]["houseRowID"] != null && ds.Tables[0].Rows[0]["houseRowID"].ToString() != "")
         {
             model.houseRowID = int.Parse(ds.Tables[0].Rows[0]["houseRowID"].ToString());
         }
         if (ds.Tables[0].Rows[0]["houseColumnID"] != null && ds.Tables[0].Rows[0]["houseColumnID"].ToString() != "")
         {
             model.houseColumnID = int.Parse(ds.Tables[0].Rows[0]["houseColumnID"].ToString());
         }
         if (ds.Tables[0].Rows[0]["name"] != null && ds.Tables[0].Rows[0]["name"].ToString() != "")
         {
             model.name = ds.Tables[0].Rows[0]["name"].ToString();
         }
         if (ds.Tables[0].Rows[0]["useStatus"] != null && ds.Tables[0].Rows[0]["useStatus"].ToString() != "")
         {
             model.useStatus = int.Parse(ds.Tables[0].Rows[0]["useStatus"].ToString());
         }
         if (ds.Tables[0].Rows[0]["productID"] != null && ds.Tables[0].Rows[0]["productID"].ToString() != "")
         {
             model.productID = ds.Tables[0].Rows[0]["productID"].ToString();
         }
         return model;
     }
     else
     {
         return null;
     }
 }
        /// <summary>
        /// 初始化仓位
        /// </summary>
        /// <returns>0:成功初始化,1:取消当前操作</returns>
        private int InitWarehouse()
        {
            this.progressBarXHouseInit.Visible = true;
            if(_warestoreBll.GetCellCount() == 0)
            {
                for (int L = 1; L <= this._layerCount; L++)
                {
                    for (int R = 1; R <= this._channelCount * 2; R++)
                    {
                        for (int C = 1; C <= this._columnCount; C++)
                        {
                            WarehouseStoreME m = new WarehouseStoreME();
                            m.houseID = _model.HouseCoordConvertID(L, R, C);
                            m.houseLayerID = L;
                            m.houseRowID = R;
                            m.houseColumnID = C;
                            m.productID = string.Empty;
                            m.name = L.ToString() + "-" + R.ToString() + "-" + C.ToString();
                            m.useStatus = 1;
                            if(!this._warestoreBll.AddHousecell(m))
                            {
                                MessageBox.Show("初始化仓位数据库失败");
                                return 1;
                            }
                            int n = (L - 1) * this._channelCount * 2 * this._columnCount + (R - 1) * this._columnCount + C;
                            this.progressBarXHouseInit.Value = (int)(n * 100.0f / (this._layerCount * this._channelCount * 2 * this._columnCount));
                        }
                    }
                }
                return 0;
            }
            else if(_warestoreBll.GetCellCount()>0)
            {
                //立库仓位在数据库中有存储记录,给出提示
                MessageBoxButtons buttons = MessageBoxButtons.YesNoCancel;
                MessageBoxIcon icon = MessageBoxIcon.Warning;
                DialogResult re = MessageBox.Show("是否保留现有记录","提示" ,buttons, icon);
                if(re == DialogResult.Yes)
                {
                    //保持现有的,仓位的ID号可能会变化
                    for (int L = 1; L <= this._layerCount; L++)
                    {
                        for (int R = 1; R <= this._channelCount* 2; R++)
                        {
                            for (int C = 1; C <= this._columnCount; C++)
                            {
                                WarehouseStoreME m = _warestoreBll.GetHouseCell(L, R, C);
                                if (m == null)
                                {
                                    //增加
                                    m = new WarehouseStoreME();
                                    m.houseLayerID = L;
                                    m.houseRowID = R;
                                    m.houseColumnID = C;
                                    m.houseID = _model.HouseCoordConvertID(L, R, C);
                                    m.useStatus = 1;
                                    m.name = L.ToString() + "-" + R.ToString() + "-" + C.ToString();
                                    m.productID = string.Empty;
                                    //增加之前先检查是否存在相同的ID,若存在则修改
                                    WarehouseStoreME oldM = _warestoreBll.GetHouseCell(m.houseID);
                                    if (oldM != null)
                                    {
                                        _warestoreBll.DeleteHouseCell(m.houseID);
                                        oldM.houseID = _model.HouseCoordConvertID(oldM.houseLayerID, oldM.houseRowID, oldM.houseColumnID);
                                        _warestoreBll.AddHousecell(oldM);
                                    }
                                    _warestoreBll.AddHousecell(m);

                                }
                                else
                                {
                                    //改变ID号
                                    int houseID = _model.HouseCoordConvertID(L, R, C);
                                    if (m.houseID != houseID)
                                    {
                                        _warestoreBll.DeleteHouseCell(m.houseID);
                                        m.houseID = houseID;
                                        _warestoreBll.AddHousecell(m);
                                    }
                                }

                                int n = (L - 1) * this._channelCount * 2 * this._columnCount + (R - 1) * this._columnCount + C;
                                this.progressBarXHouseInit.Value = (int)(n * 100.0f / (this._layerCount * this._channelCount * 2 * this._columnCount));
                            }
                        }
                    }
                    return 0;
                }
                else if(re == DialogResult.No)
                {
                    //清理掉
                    _warestoreBll.ClearAllData();
                    for (int L = 1; L <= this._layerCount; L++)
                    {
                        for (int R = 1; R <= this._channelCount * 2; R++)
                        {
                            for (int C = 1; C <= this._columnCount; C++)
                            {
                                WarehouseStoreME m = new WarehouseStoreME();
                                m.houseID = _model.HouseCoordConvertID(L, R, C);
                                m.houseLayerID = L;
                                m.houseRowID = R;
                                m.houseColumnID = C;
                                m.productID = string.Empty;
                                m.name = L.ToString() + "-" + R.ToString() + "-" + C.ToString();
                                m.useStatus = 1;
                                this._warestoreBll.AddHousecell(m);
                                int n = (L - 1) * this._channelCount * 2 * this._columnCount + (R - 1) * this._columnCount + C;
                                this.progressBarXHouseInit.Value = (int)(n * 100.0f / (this._layerCount * this._channelCount * 2 * this._columnCount));
                            }
                        }
                    }
                    return 0;
                }
                else
                {
                    //取消
                    return 1;
                }
            }
            return 1;
        }