/// <summary> /// 获取查询语句 /// </summary> /// <param name="user">查询条件</param> /// <param name="parameters">参数</param> /// <returns>查询语句</returns> private string GetQuerySql(WHSpec condition, ref List <DataParameter> parameters) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); try { //构成查询语句 sqlBuilder.Append("SELECT ID,Description,Remark,CREATEUSER,CREATETIME,UPDATEUSER,UPDATETIME "); sqlBuilder.Append("FROM T_WH_Spec "); if (string.IsNullOrEmpty(condition.Description) == false) { whereBuilder.Append(" AND Description like @Description"); parameters.Add(new DataParameter("Description", "%" + condition.Description + "%")); } //查询条件 if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } return(sqlBuilder.ToString()); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取列表 /// </summary> /// <param name="condition">条件</param> /// <param name="page">数据页</param> /// <returns>数据页</returns> public DataPage GetList(WHSpec condition, DataPage page) { string sql = null; List <DataParameter> parameters = new List <DataParameter>(); try { sql = this.GetQuerySql(condition, ref parameters); //分页关键字段及排序 page.KeyName = "ID"; if (string.IsNullOrEmpty(page.SortExpression)) { page.SortExpression = "UPDATETIME DESC"; } using (IDataSession session = AppDataFactory.CreateMainSession()) { page = session.GetDataPage <WHSpec>(sql, parameters.ToArray(), page); } return(page); } catch (Exception ex) { throw ex; } }
/// <summary> /// 插入信息(单表) /// </summary> /// <param name="">信息</param> /// <returns>插入行数</returns> public DataResult <int> Insert(WHSpec model) { DataResult <int> result = new DataResult <int>(); try { //基本信息 model.ID = Guid.NewGuid().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATETIME = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATETIME = model.CREATETIME; if (Exists(model)) { result.Msg = "名称已存在"; result.Result = -1; return(result); } result.Result = new WHSpecDAL().Insert(model); result.IsSuccess = true; return(result); } catch (Exception ex) { throw ex; } }
private void BindData() { WHSpecBLL bll = null; DataPage dp = new DataPage(); WHSpec condition = new WHSpec(); try { bll = BLLFactory.CreateBLL <WHSpecBLL>(); condition.Description = this.Description.Text; PagerHelper.InitPageControl(this.AspNetPager1, dp, true); dp = bll.GetList(condition, dp); List <WHSpec> list = dp.Result as List <WHSpec>; this.GvList.DataSource = list; this.GvList.DataBind(); for (int i = 0; i < this.GvList.Rows.Count; i++) { string click = string.Format("return edit('{0}');", this.GvList.DataKeys[i]["ID"].ToString()); (this.GvList.Rows[i].Cells[3].Controls[0] as WebControl).Attributes.Add("onclick", click); } PagerHelper.SetPageControl(AspNetPager1, dp, true); } catch (Exception ex) { throw ex; } }
private void BindData() { string id = Request.QueryString["id"]; WHSpecBLL bll = null; WHSpec info = new WHSpec(); try { bll = BLLFactory.CreateBLL <WHSpecBLL>(); if (string.IsNullOrEmpty(id) == false) { info.ID = id; info = bll.Get(info); UIBindHelper.BindForm(this.Page, info); this.hiID.Value = info.ID; this.HiCREATEUSER.Value = info.CREATEUSER; this.HiCREATETIME.Value = info.CREATETIME.ToString(); } else { info = new WHSpec(); } } catch (Exception ex) { throw ex; } }
protected void btSave_Click(object sender, EventArgs e) { WHSpec info = new WHSpec(); WHSpecBLL bll = null; try { UIBindHelper.BindModelByControls(this.Page, info); bll = BLLFactory.CreateBLL <WHSpecBLL>(); if (this.hiID.Value == "") { bll.Insert(info); } else { info.CREATEUSER = this.HiCREATEUSER.Value; info.CREATETIME = DateTime.Parse(this.HiCREATETIME.Value); info.ID = this.hiID.Value; bll.Update(info); } ClientScript.RegisterStartupScript(this.GetType(), "myjs", "parent.refreshData();parent.closeAppWindow1();", true); } catch (Exception ex) { throw ex; } }
/// <summary> /// 判断名称是否存在 /// </summary> /// <param name="">信息</param> /// <returns>true:已存在;fasel:不存在。</returns> public bool Exists(WHSpec model) { try { return(new WHSpecDAL().Exists(model)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取列表 /// </summary> /// <param name="condition">条件</param> /// <param name="page">数据页</param> /// <returns>数据页</returns> public DataPage GetList(WHSpec condition, DataPage page) { try { return(new WHSpecDAL().GetList(condition, page)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取信息 /// </summary> /// <param name="">条件</param> /// <returns>信息</returns> public WHSpec Get(WHSpec model) { try { return(new WHSpecDAL().Get(model)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取导出的数据 /// </summary> /// <param name="">查询条件</param> /// <returns>数据</returns> public DataTable GetExportData(WHSpec model) { try { return(new WHSpecDAL().GetExportData(model)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 删除信息 /// </summary> /// <param name="">信息</param> /// <returns>删除个数</returns> public int Delete(WHSpec model) { try { return(new WHSpecDAL().Delete(model)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取列表 /// </summary> /// <param name="condition">条件</param> /// <returns>仓库列表</returns> public List <WHSpec> GetList(WHSpec condition) { List <WHSpec> list = null; string sql = null; using (IDataSession session = AppDataFactory.CreateMainSession()) { sql = "SELECT ID,Description FROM T_WH_Spec order by Description"; list = session.GetList <WHSpec>(sql, new List <DataParameter>().ToArray()).ToList <WHSpec>(); } return(list); }
/// <summary> /// 获取信息 /// </summary> /// <param name="">条件</param> /// <returns>*信息</returns> public WHSpec Get(WHSpec model) { try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //获取信息 model = session.Get <WHSpec>(model); } return(model); } catch (Exception ex) { throw ex; } }
/// <summary> /// 更新信息 /// </summary> /// <param name=""></param> /// <returns>更新行数</returns> public int Update(WHSpec model) { int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { //更新信息 count = session.Update <WHSpec>(model); } return(count); } catch (Exception ex) { throw ex; } }
/// <summary> /// 删除 /// </summary> /// <param name=""></param> /// <returns>删除个数</returns> public int Delete(WHSpec model) { StringBuilder sqlBuilder = new StringBuilder(); List <DataParameter> parameters = new List <DataParameter>(); int count = 0; try { using (IDataSession session = AppDataFactory.CreateMainSession()) { count = session.Delete <WHSpec>(model); } return(count); } catch (Exception ex) { throw ex; } }
/// <summary> /// 更新信息 /// </summary> /// <param name="">信息</param> /// <returns>更新行数</returns> public DataResult <int> Update(WHSpec model) { DataResult <int> result = new DataResult <int>(); try { if (Exists(model)) { result.Msg = "名称已存在"; result.Result = -1; return(result); } model.UPDATEUSER = this.LoginUser.UserID; result.Result = new WHSpecDAL().Update(model); result.IsSuccess = true; return(result); } catch (Exception ex) { throw ex; } }
/// <summary> /// 获取导出的数据 /// </summary> /// <param name="user">查询条件</param> /// <returns>数据</returns> public DataTable GetExportData(WHSpec model) { DataTable dt = null; string sql = null; List <DataParameter> parameters = new List <DataParameter>(); try { //构成查询语句 sql = this.GetQuerySql(model, ref parameters); using (IDataSession session = AppDataFactory.CreateMainSession()) { dt = session.GetTable(sql, parameters.ToArray()); dt.TableName = "Warehouse"; } return(dt); } catch (Exception ex) { throw ex; } }
/// <summary> /// 判断名称是否存在 /// </summary> /// <param name="info"></param> /// <returns>true:已存在;fasel:不存在。</returns> public bool Exists(WHSpec model) { StringBuilder sqlBuilder = new StringBuilder(); StringBuilder whereBuilder = new StringBuilder(); List <DataParameter> parameters = new List <DataParameter>(); int count = 0; try { sqlBuilder.Append("SELECT COUNT(0) FROM T_WH_Spec"); whereBuilder.Append(" AND ID <> @ID "); parameters.Add(new DataParameter { ParameterName = "ID", DataType = DbType.String, Value = model.ID }); if (!string.IsNullOrEmpty(model.Description)) { whereBuilder.Append(" AND Description = @Description "); parameters.Add(new DataParameter { ParameterName = "Description", DataType = DbType.String, Value = model.Description }); } if (whereBuilder.Length > 0) { sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4)); } using (IDataSession session = AppDataFactory.CreateMainSession()) { string sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session); count = Convert.ToInt32(session.ExecuteSqlScalar(sql, parameters.ToArray())); } return(count > 0); } catch (Exception ex) { throw ex; } }