/// <summary> /// Hàm lấy danh sách objtblmathang /// </summary> /// <param name="recperpage">Số lượng bản ghi kiểu integer</param> /// <param name="pageindex">Số trang kiểu integer</param> /// <returns>Trả về List<<tblmathang>></returns> public List <tblmathang> GetListPaged(int recperpage, int pageindex) { List <tblmathang> list = new List <tblmathang>(); string strFun = "fn_tblmathang_getpaged"; try { NpgsqlParameter[] prmArr = new NpgsqlParameter[2]; prmArr[0] = new NpgsqlParameter("recperpage", NpgsqlDbType.Integer); prmArr[0].Value = recperpage; prmArr[1] = new NpgsqlParameter("pageindex", NpgsqlDbType.Integer); prmArr[1].Value = pageindex; DataSet dstblmathang = mDataAccess.ExecuteDataSet(strFun, CommandType.StoredProcedure, prmArr); if ((dstblmathang != null) && (dstblmathang.Tables.Count > 0)) { for (int i = 0; i < dstblmathang.Tables[0].Rows.Count; i++) { tblmathang objtblmathang = new tblmathang(); DataRow dr = dstblmathang.Tables[0].Rows[i]; objtblmathang.id = dr["id"].ToString(); objtblmathang.id_hangsx = dr["id_hangsx"].ToString(); objtblmathang.id_loai = dr["id_loai"].ToString(); objtblmathang.ten = dr["ten"].ToString(); try { objtblmathang.gianhap = Convert.ToDouble("0" + dr["gianhap"].ToString()); } catch { objtblmathang.gianhap = 0; } try{ objtblmathang.soluong = Convert.ToInt32("0" + dr["soluong"].ToString()); } catch { objtblmathang.soluong = 0; } objtblmathang.donvi = dr["donvi"].ToString(); objtblmathang.ghichu = dr["ghichu"].ToString(); try { objtblmathang.giabanbuon = Convert.ToDouble("0" + dr["giabanbuon"].ToString()); } catch { objtblmathang.giabanbuon = 0; } try { objtblmathang.giabanle = Convert.ToDouble("0" + dr["giabanle"].ToString()); } catch { objtblmathang.giabanle = 0; } try { objtblmathang.giadl1 = Convert.ToDouble("0" + dr["giadl1"].ToString()); } catch { objtblmathang.giadl1 = 0; } try { objtblmathang.giadl2 = Convert.ToDouble("0" + dr["giadl2"].ToString()); } catch { objtblmathang.giadl2 = 0; } try { objtblmathang.giadl3 = Convert.ToDouble("0" + dr["giadl3"].ToString()); } catch { objtblmathang.giadl3 = 0; } try { objtblmathang.giadl4 = Convert.ToDouble("0" + dr["giadl4"].ToString()); } catch { objtblmathang.giadl4 = 0; } try { objtblmathang.giadl5 = Convert.ToDouble("0" + dr["giadl5"].ToString()); } catch { objtblmathang.giadl5 = 0; } objtblmathang.tenkhongdau = dr["tenkhongdau"].ToString(); try { objtblmathang.ngaynhap = Convert.ToDateTime(dr["ngaynhap"].ToString()); } catch { objtblmathang.ngaynhap = new DateTime(1900, 1, 1); } objtblmathang.userid = dr["userid"].ToString(); list.Add(objtblmathang); } return(list); } return(null); } catch { return(null); } }
/// <summary> /// Cập nhật dữ liệu vào bảng: tblmathang /// </summary> /// <param name="obj">objtblmathang</param> /// <returns>Trả về trắng: Cập nhật thành công; Trả về khác trắng: Cập nhật không thành công</returns> public string Update(tblmathang objtblmathang) { string strProc = "fn_tblmathang_Update"; try { NpgsqlParameter[] prmArr = new NpgsqlParameter[21]; prmArr[0] = new NpgsqlParameter("id", NpgsqlDbType.Varchar); prmArr[0].Value = objtblmathang.strid; prmArr[1] = new NpgsqlParameter("id_hangsx", NpgsqlDbType.Varchar); prmArr[1].Value = objtblmathang.strid_hangsx; prmArr[2] = new NpgsqlParameter("id_loai", NpgsqlDbType.Varchar); prmArr[2].Value = objtblmathang.strid_loai; prmArr[3] = new NpgsqlParameter("ten", NpgsqlDbType.Varchar); prmArr[3].Value = objtblmathang.strten; prmArr[4] = new NpgsqlParameter("gianhap", NpgsqlDbType.Double); prmArr[4].Value = objtblmathang.dblgianhap; prmArr[5] = new NpgsqlParameter("soluong", NpgsqlDbType.Integer); prmArr[5].Value = objtblmathang.intsoluong; prmArr[6] = new NpgsqlParameter("donvi", NpgsqlDbType.Varchar); prmArr[6].Value = objtblmathang.strdonvi; prmArr[7] = new NpgsqlParameter("ghichu", NpgsqlDbType.Varchar); prmArr[7].Value = objtblmathang.strghichu; prmArr[8] = new NpgsqlParameter("giabanbuon", NpgsqlDbType.Double); prmArr[8].Value = objtblmathang.dblgiabanbuon; prmArr[9] = new NpgsqlParameter("giabanle", NpgsqlDbType.Double); prmArr[9].Value = objtblmathang.dblgiabanle; prmArr[10] = new NpgsqlParameter("giadl1", NpgsqlDbType.Double); prmArr[10].Value = objtblmathang.dblgiadl1; prmArr[11] = new NpgsqlParameter("giadl2", NpgsqlDbType.Double); prmArr[11].Value = objtblmathang.dblgiadl2; prmArr[12] = new NpgsqlParameter("giadl3", NpgsqlDbType.Double); prmArr[12].Value = objtblmathang.dblgiadl3; prmArr[13] = new NpgsqlParameter("giadl4", NpgsqlDbType.Double); prmArr[13].Value = objtblmathang.dblgiadl4; prmArr[14] = new NpgsqlParameter("giadl5", NpgsqlDbType.Double); prmArr[14].Value = objtblmathang.dblgiadl5; prmArr[15] = new NpgsqlParameter("tenkhongdau", NpgsqlDbType.Text); prmArr[15].Value = objtblmathang.strtenkhongdau; prmArr[16] = new NpgsqlParameter("userid", NpgsqlDbType.Varchar); prmArr[16].Value = objtblmathang.struserid; prmArr[17] = new NpgsqlParameter("mavach", NpgsqlDbType.Varchar); prmArr[17].Value = objtblmathang.strmavach; prmArr[18] = new NpgsqlParameter("giamua", NpgsqlDbType.Double); prmArr[18].Value = objtblmathang.dbgiamua; prmArr[19] = new NpgsqlParameter("giavanchuyen", NpgsqlDbType.Double); prmArr[19].Value = objtblmathang.dbgiavanchuyen; prmArr[20] = new NpgsqlParameter("ireturn", NpgsqlDbType.Text); prmArr[20].Direction = ParameterDirection.Output; mDataAccess.ExecuteQuery(strProc, CommandType.StoredProcedure, prmArr); string sKQ = prmArr[20].Value.ToString().Trim(); if (sKQ.ToUpper().Equals("Update".ToUpper()) == true) { return(""); } return("Cập nhật dữ liệu không thành công"); } catch (Exception ex) { return("Cập nhật dữ liệu không thành công. Chi Tiết: " + ex.Message); } }
/// <summary> /// Hàm lấy tất cả dữ liệu trong bảng tblmathang /// </summary> /// <returns>Trả về List<<tblmathang>></returns> public List <tblmathang> GetList() { List <tblmathang> list = new List <tblmathang>(); string strFun = "fn_tblmathang_getall"; try { DataSet dstblmathang = mDataAccess.ExecuteDataSet(strFun, CommandType.StoredProcedure); if ((dstblmathang != null) && (dstblmathang.Tables.Count > 0)) { for (int i = 0; i < dstblmathang.Tables[0].Rows.Count; i++) { tblmathang objtblmathang = new tblmathang(); DataRow dr = dstblmathang.Tables[0].Rows[i]; objtblmathang.id = dr["id"].ToString(); objtblmathang.id_hangsx = dr["id_hangsx"].ToString(); objtblmathang.id_loai = dr["id_loai"].ToString(); objtblmathang.ten = dr["ten"].ToString(); try { objtblmathang.gianhap = Convert.ToDouble("0" + dr["gianhap"].ToString()); } catch { objtblmathang.gianhap = 0; } try{ objtblmathang.soluong = Convert.ToInt32("0" + dr["soluong"].ToString()); } catch { objtblmathang.soluong = 0; } objtblmathang.donvi = dr["donvi"].ToString(); objtblmathang.ghichu = dr["ghichu"].ToString(); try { objtblmathang.giabanbuon = Convert.ToDouble("0" + dr["giabanbuon"].ToString()); } catch { objtblmathang.giabanbuon = 0; } try { objtblmathang.giabanle = Convert.ToDouble("0" + dr["giabanle"].ToString()); } catch { objtblmathang.giabanle = 0; } try { objtblmathang.giadl1 = Convert.ToDouble("0" + dr["giadl1"].ToString()); } catch { objtblmathang.giadl1 = 0; } try { objtblmathang.giadl2 = Convert.ToDouble("0" + dr["giadl2"].ToString()); } catch { objtblmathang.giadl2 = 0; } try { objtblmathang.giadl3 = Convert.ToDouble("0" + dr["giadl3"].ToString()); } catch { objtblmathang.giadl3 = 0; } try { objtblmathang.giadl4 = Convert.ToDouble("0" + dr["giadl4"].ToString()); } catch { objtblmathang.giadl4 = 0; } try { objtblmathang.giadl5 = Convert.ToDouble("0" + dr["giadl5"].ToString()); } catch { objtblmathang.giadl5 = 0; } objtblmathang.tenkhongdau = dr["tenkhongdau"].ToString(); try { objtblmathang.ngaynhap = Convert.ToDateTime(dr["ngaynhap"].ToString()); } catch { objtblmathang.ngaynhap = new DateTime(1900, 1, 1); } objtblmathang.userid = dr["userid"].ToString(); list.Add(objtblmathang); } return(list); } return(null); } catch { return(null); } }
/// <summary> /// Hàm lấy tblmathang theo mã /// </summary> /// <returns>Trả về objtblmathang </returns> public tblmathang GetByID(string strid) { tblmathang objtblmathang = new tblmathang(); string strFun = "fn_tblmathang_getobjbyid"; try { NpgsqlParameter[] prmArr = new NpgsqlParameter[1]; prmArr[0] = new NpgsqlParameter("id", NpgsqlDbType.Varchar); prmArr[0].Value = strid; DataSet dstblmathang = mDataAccess.ExecuteDataSet(strFun, CommandType.StoredProcedure, prmArr); if ((dstblmathang != null) && (dstblmathang.Tables.Count > 0)) { if (dstblmathang.Tables[0].Rows.Count > 0) { DataRow dr = dstblmathang.Tables[0].Rows[0]; objtblmathang.id = dr["id"].ToString(); objtblmathang.id_hangsx = dr["id_hangsx"].ToString(); objtblmathang.id_loai = dr["id_loai"].ToString(); objtblmathang.ten = dr["ten"].ToString(); try { objtblmathang.gianhap = Convert.ToDouble("0" + dr["gianhap"].ToString()); } catch { objtblmathang.gianhap = 0; } try{ objtblmathang.soluong = Convert.ToInt32("0" + dr["soluong"].ToString()); } catch { objtblmathang.soluong = 0; } objtblmathang.donvi = dr["donvi"].ToString(); objtblmathang.ghichu = dr["ghichu"].ToString(); try { objtblmathang.giabanbuon = Convert.ToDouble("0" + dr["giabanbuon"].ToString()); } catch { objtblmathang.giabanbuon = 0; } try { objtblmathang.giabanle = Convert.ToDouble("0" + dr["giabanle"].ToString()); } catch { objtblmathang.giabanle = 0; } try { objtblmathang.giadl1 = Convert.ToDouble("0" + dr["giadl1"].ToString()); } catch { objtblmathang.giadl1 = 0; } try { objtblmathang.giadl2 = Convert.ToDouble("0" + dr["giadl2"].ToString()); } catch { objtblmathang.giadl2 = 0; } try { objtblmathang.giadl3 = Convert.ToDouble("0" + dr["giadl3"].ToString()); } catch { objtblmathang.giadl3 = 0; } try { objtblmathang.giadl4 = Convert.ToDouble("0" + dr["giadl4"].ToString()); } catch { objtblmathang.giadl4 = 0; } try { objtblmathang.giadl5 = Convert.ToDouble("0" + dr["giadl5"].ToString()); } catch { objtblmathang.giadl5 = 0; } objtblmathang.tenkhongdau = dr["tenkhongdau"].ToString(); try { objtblmathang.ngaynhap = Convert.ToDateTime(dr["ngaynhap"].ToString()); } catch { objtblmathang.ngaynhap = new DateTime(1900, 1, 1); } objtblmathang.userid = dr["userid"].ToString(); return(objtblmathang); } return(null); } return(null); } catch { return(null); } }