/// <summary>
 ///  ����һ������
 /// </summary>
 public void Add(BrandModel model)
 {
     DbCommand dbCommand = dbw.GetStoredProcCommand("UP_pdBrand_ADD");
     dbw.AddInParameter(dbCommand, "BrandId", DbType.Int32, model.BrandId);
     dbw.AddInParameter(dbCommand, "BrandName", DbType.AnsiString, model.BrandName);
     dbw.AddInParameter(dbCommand, "CateId", DbType.Int32, model.CateId);
     dbw.AddInParameter(dbCommand, "CatePath", DbType.AnsiString, model.CatePath);
     dbw.AddInParameter(dbCommand, "BrandLogo", DbType.AnsiString, model.BrandLogo);
     dbw.AddInParameter(dbCommand, "Brief", DbType.AnsiString, model.Brief);
     dbw.AddInParameter(dbCommand, "showorder", DbType.Int32, model.ShowOrder);
     dbw.AddInParameter(dbCommand, "pinyinname", DbType.String, model.PinYinName);
     dbw.ExecuteNonQuery(dbCommand);
 }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string strErr = "";
            if (this.txtBrandName.Text == "")
            {
                strErr += "Ʒ�����Ʋ���Ϊ�գ�\\n";
            }
            if (this.fulBrandLogo.FileName == "")
            {
                strErr += "Ʒ�Ʊ�־����Ϊ�գ�\\n";
            }
            if (this.txtBrief.Text == "")
            {
                strErr += "��Ҫ���ܲ���Ϊ�գ�\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }

            if (bll.Exists(txtBrandName.Text))
            {
                MessageBox.Show(this,"��Ʒ���Ѵ���");
                return;
            }

            BrandModel model = new BrandModel();

            model.BrandId = CommDataHelper.GetNewSerialNum("pd");
            model.BrandName = txtBrandName.Text;
            model.BrandLogo = UploadBrandLogo(model.BrandId, fulBrandLogo);
            model.Brief = txtBrief.Text;
            model.ShowOrder = model.BrandId;

            bll.Add(model);
            Response.Redirect("List.aspx");
        }
        private BrandModel GetModel(DataRow row)
        {
            BrandModel model = new BrandModel();

            model.BrandId = int.Parse(row["BrandId"].ToString());
            model.BrandName = row["BrandName"].ToString();
            model.CateId = int.Parse(row["CateId"].ToString());
            model.CatePath = row["CatePath"].ToString();
            model.BrandLogo = row["BrandLogo"].ToString();
            model.Brief = row["Brief"].ToString();
            model.ShowOrder = int.Parse(row["showorder"].ToString());

            return model;
        }
 /// <summary>
 /// ����ʵ�������
 /// </summary>
 public BrandModel ReaderBind(IDataReader dataReader)
 {
     BrandModel model=new BrandModel();
     object ojb;
     ojb = dataReader["BrandId"];
     if(ojb != null && ojb != DBNull.Value)
     {
         model.BrandId=(int)ojb;
     }
     model.BrandName=dataReader["BrandName"].ToString();
     ojb = dataReader["CateId"];
     if(ojb != null && ojb != DBNull.Value)
     {
         model.CateId=(int)ojb;
     }
     model.CatePath=dataReader["CatePath"].ToString();
     model.BrandLogo=dataReader["BrandLogo"].ToString();
     model.Brief=dataReader["Brief"].ToString();
     model.ShowOrder = int.Parse(dataReader["showorder"].ToString());
     return model;
 }
        public bool RawExists(string BrandName,out BrandModel model)
        {
            DbCommand Command = dbr.GetSqlStringCommand("select top 1 * from pdbrand where brandname like @brandname");

            dbr.AddInParameter(Command,"@brandname",DbType.String, "%" + BrandName + "%");

            DataTable dt = dbr.ExecuteDataSet(Command).Tables[0];
            if (dt.Rows.Count > 0)
            {
                model = GetModel(dt.Rows[0]);
                return true;
            }
            else
            {
                model = null;
                return false;
            }
        }
 /// <summary>
 /// ����һ������
 /// </summary>
 public void Add(BrandModel model)
 {
     dal.Add(model);
 }
 /// <summary>
 /// ����һ������
 /// </summary>
 public void Update(BrandModel model)
 {
     dal.Update(model);
 }
 public bool RawExists(string BrandName, out BrandModel model)
 {
     return dal.RawExists(BrandName,out model);
 }
 /// <summary>
 /// ��������б�
 /// </summary>
 public List<BrandModel> GetModelList(string strWhere)
 {
     DataSet ds = dal.GetList(strWhere, String.Empty);
     List<BrandModel> modelList = new List<BrandModel>();
     int rowsCount = ds.Tables[0].Rows.Count;
     if (rowsCount > 0)
     {
         BrandModel model;
         for (int n = 0; n < rowsCount; n++)
         {
             model = new BrandModel();
             if(ds.Tables[0].Rows[n]["BrandId"].ToString()!="")
             {
                 model.BrandId=int.Parse(ds.Tables[0].Rows[n]["BrandId"].ToString());
             }
             model.BrandName=ds.Tables[0].Rows[n]["BrandName"].ToString();
             if(ds.Tables[0].Rows[n]["CateId"].ToString()!="")
             {
                 model.CateId=int.Parse(ds.Tables[0].Rows[n]["CateId"].ToString());
             }
             model.CatePath=ds.Tables[0].Rows[n]["CatePath"].ToString();
             model.BrandLogo=ds.Tables[0].Rows[n]["BrandLogo"].ToString();
             model.Brief=ds.Tables[0].Rows[n]["Brief"].ToString();
             modelList.Add(model);
         }
     }
     return modelList;
 }