/// <summary> /// 从一个OleDbDataReader里读数据 /// </summary> /// <param name="Reader">OleDbDataReader</param> /// <returns>return_goodsExample</returns> public static return_goods GetByReader(OleDbDataReader Reader) { return_goods return_goodsExample = new return_goods(); return_goodsExample.cid = Reader["cid"] == DBNull.Value ? 0 : (int)Reader["cid"]; return_goodsExample.cname = Reader["cname"] == DBNull.Value ? null : Reader["cname"].ToString(); return_goodsExample.rgcode = Reader["rgcode"] == DBNull.Value ? null : Reader["rgcode"].ToString(); return_goodsExample.rgdate = Reader["rgdate"] == DBNull.Value ? new DateTime() : Convert.ToDateTime(Reader["rgdate"]); return_goodsExample.rgid = Reader["rgid"] == DBNull.Value ? 0 : (int)Reader["rgid"]; return_goodsExample.rgremark = Reader["rgremark"] == DBNull.Value ? null : Reader["rgremark"].ToString(); return(return_goodsExample); }
/// <summary> /// 查询全部数据 /// </summary> /// <returns>IList</returns> /*查看是否为视图*/ public IList <return_goods> SearchAll() { Access.DBHelper.sqlstr = "select * from return_goods "; List <return_goods> list = new List <return_goods>(); OleDbDataReader reader = Access.DBHelper.ExecuteReader(); while (reader.Read()) { return_goods Obj = GetByReader(reader); list.Add(Obj); } reader.Close(); return(list); }
protected void btn_save_Click(object sender, EventArgs e) { try { string name = txt_name.Text.Trim(); string courier = ddl_courier.SelectedValue.ToString(); string remark = txt_remark.Text.Trim(); return_goods sp = new return_goods(); if (!string.IsNullOrEmpty(id)) { sp = BLL.return_goodsManager.SearchByID(Convert.ToInt32(id)); } else { sp.rgdate = DateTime.Now; } sp.rgcode = name; sp.rgremark = remark; sp.cid = Convert.ToInt32(courier); sp.cname = ddl_courier.SelectedItem.Text; int res = 0; if (string.IsNullOrEmpty(id)) { res = BLL.return_goodsManager.Insert(sp); } else { res = BLL.return_goodsManager.Update(sp); } if (res == 1) { //AJAXManager.Alert(UpdatePanel1, "保存成功"); lbl_message.Text = "快递单号: " + name + " <br/>信息状态: 保存成功! "; } else { //AJAXManager.Alert(UpdatePanel1, "保存失败"); lbl_message.Text = "保存失败,请联系张建"; } Manager.TextBox_Select(txt_name); } catch (Exception ex) { Manager.Alert(ex.ToString(), Page); } Manager.page_href_reload(Page); }
/// <summary> /// 根据表,获取一个OleDbParameter数组 /// </summary> /// <returns>OleDbParameter[]</returns> public static OleDbParameter[] GetOleDbParameter(return_goods return_goodsExample) { List <OleDbParameter> list_param = new List <OleDbParameter>(); if (return_goodsExample.cid != 0) { list_param.Add(new OleDbParameter("@cid", return_goodsExample.cid)); } else { list_param.Add(new OleDbParameter("@cid", DBNull.Value)); } if (!string.IsNullOrEmpty(return_goodsExample.cname)) { list_param.Add(new OleDbParameter("@cname", return_goodsExample.cname)); } else { list_param.Add(new OleDbParameter("@cname", DBNull.Value)); } if (!string.IsNullOrEmpty(return_goodsExample.rgcode)) { list_param.Add(new OleDbParameter("@rgcode", return_goodsExample.rgcode)); } else { list_param.Add(new OleDbParameter("@rgcode", DBNull.Value)); } if (!string.IsNullOrEmpty(return_goodsExample.rgremark)) { list_param.Add(new OleDbParameter("@rgremark", return_goodsExample.rgremark)); } else { list_param.Add(new OleDbParameter("@rgremark", DBNull.Value)); } OleDbParameter[] param = new OleDbParameter[list_param.Count]; int index = 0; foreach (OleDbParameter p in list_param) { param[index] = p; index++; } return(param); }
/// <summary> /// 根据rgid,查询一条数据 /// </summary> /// <param name="rgid">退货编号</param> /// <returns></returns> public return_goods SearchByID(int rgid) { Access.DBHelper.sqlstr = "select * from return_goods where rgid = @rgid"; OleDbParameter[] param = new OleDbParameter[] { new OleDbParameter("@rgid", rgid) }; OleDbDataReader reader = Access.DBHelper.ExecuteReader(param); return_goods Obj = null; if (reader.Read()) { Obj = GetByReader(reader); } reader.Close(); return(Obj); }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { TextBox txt_code = GridView1.Rows[e.RowIndex].FindControl("txt_code") as TextBox; TextBox txt_remark = GridView1.Rows[e.RowIndex].FindControl("txt_remark") as TextBox; int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["rgid"]); return_goods sa = BLL.return_goodsManager.SearchByID(id); sa.rgcode = txt_code.Text.Trim(); sa.rgremark = txt_remark.Text.Trim(); if (BLL.return_goodsManager.Update(sa) != 1) { AJAXManager.Alert(this.UpdatePanel1, "修改失败"); } else { GridView1.EditIndex = -1; bind(); } }
/// <summary> /// 根据条件查询全部数据 /// </summary> /// <param name="s">起始位置</param> /// <param name="e">结束位置</param> /// <param name="key">关键词</param> /// <param name="state">状态</param> /// <param name="date1">起始时间</param> /// <param name="date2">结束时间</param> /// <returns>IList<return_goods></returns> public IList <return_goods> Search(int s, int e, string key, string cid, DateTime date1, DateTime date2) { string sql1 = "select top " + e.ToString() + " * from return_goods where "; string sql2 = string.IsNullOrEmpty(key) ? " 1=1 " : " ( cname like '%"+ key + "%' or rgcode like '%" + key + "%' or rgremark like '%" + key + "%' ) "; string sql3 = date1 == new DateTime() ? "" : " and datediff('d','" + date1.ToString() + "',rgdate)>=0 "; string sql4 = date2 == new DateTime() ? "" : " and datediff('d','" + date2.ToString() + "',rgdate)<=0 "; string sql6 = string.IsNullOrEmpty(cid) ? "" : " and cid= " + cid; string sql5 = " order by rgid asc,rgdate asc ";//排序两个字段,否则数据容易错误 DBHelper.sqlstr = "select * from(select top " + (e - s + 1).ToString() + " * from ( " + sql1 + sql2 + sql3 + sql4 + sql6 + " order by rgid desc,rgdate asc ) " + sql5 + ") order by rgid desc,rgdate asc "; List <return_goods> list = new List <return_goods>(); OleDbDataReader reader = DBHelper.ExecuteReader(); while (reader.Read()) { return_goods Obj = GetByReader(reader); list.Add(Obj); } reader.Close(); return(list); }
void bind() { if (!string.IsNullOrEmpty(id)) { int temp = 0; if (int.TryParse(id, out temp)) { return_goods rg = BLL.return_goodsManager.SearchByID(temp); if (rg != null) { try { ddl_courier.SelectedValue = rg.cid.ToString(); txt_name.Text = rg.rgcode; txt_remark.Text = rg.rgremark; liter_date.Text = rg.rgdate.ToString(); } catch { } } } } }
/// <summary> /// 更新 /// </summary> /// <param name="return_goods">return_goods表实例</param> /// <returns>int</returns> public int Update(return_goods return_goodsExample) { Access.DBHelper.sqlstr = "update return_goods set cid=@cid,cname=@cname,rgcode=@rgcode,rgdate='" + return_goodsExample.rgdate.ToString() + "',rgremark=@rgremark where rgid=" + return_goodsExample.rgid; return(Access.DBHelper.ExecuteNonQuery(GetOleDbParameter(return_goodsExample))); }
/// <summary> /// 插入方法 /// </summary> /// <param name="return_goods">return_goods表实例</param> /// <returns>int</returns> public int Insert(return_goods return_goodsExample) { Access.DBHelper.sqlstr = "insert into return_goods (cid,cname,rgcode,rgdate,rgremark)values(@cid,@cname,@rgcode,'" + return_goodsExample.rgdate.ToString() + "',@rgremark)"; return(Access.DBHelper.ExecuteNonQuery(GetOleDbParameter(return_goodsExample))); }
/// <summary> /// 更新 /// </summary> /// <param name="return_goods">return_goods表实例</param> /// <returns>int</returns> public static int Update(return_goods return_goodsExample) { return(Service.Update(return_goodsExample)); }
/// <summary> /// 插入方法 /// </summary> /// <param name="return_goods">return_goods表实例</param> /// <returns>int</returns> public static int Insert(return_goods return_goodsExample) { return(Service.Insert(return_goodsExample)); }