/// <summary> /// 得到一个对象实体 /// </summary> public MesWeb.Model.T_AllReport DataRowToModel(DataRow row) { MesWeb.Model.T_AllReport model = new MesWeb.Model.T_AllReport(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["ReportValue"] != null) { model.ReportValue = row["ReportValue"].ToString(); } if (row["IndexValue"] != null) { model.IndexValue = row["IndexValue"].ToString(); } if (row["ReportType"] != null) { model.ReportType = row["ReportType"].ToString(); } if (row["InputDate"] != null && row["InputDate"].ToString() != "") { model.InputDate = DateTime.Parse(row["InputDate"].ToString()); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(MesWeb.Model.T_AllReport model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_AllReport("); strSql.Append("ReportValue,IndexValue,ReportType,InputDate,Remark)"); strSql.Append(" values ("); strSql.Append("@ReportValue,@IndexValue,@ReportType,@InputDate,@Remark)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ReportValue", SqlDbType.NVarChar, -1), new SqlParameter("@IndexValue", SqlDbType.NVarChar, -1), new SqlParameter("@ReportType", SqlDbType.NVarChar, -1), new SqlParameter("@InputDate", SqlDbType.DateTime), new SqlParameter("@Remark", SqlDbType.NVarChar, -1) }; parameters[0].Value = model.ReportValue; parameters[1].Value = model.IndexValue; parameters[2].Value = model.ReportType; parameters[3].Value = model.InputDate; parameters[4].Value = model.Remark; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private bool addReport(List <string> data, List <int> index, string type, List <string> remark) { try { if (data != null && data.Count > 0 && type != null) { MesWeb.Model.T_AllReport report = new MesWeb.Model.T_AllReport(); string dataStr = ""; //内容数据 data.ForEach(d => { dataStr = dataStr + spliter + d; }); dataStr = dataStr.Substring(spliter.Length); //索引数据 string indexStr = ""; index.ForEach(i => { indexStr = indexStr + spliter + data[i]; }); indexStr = indexStr.Substring(spliter.Length); //备注数据 string remarkStr = ""; if (remark != null && remark.Count > 0) { remark.ForEach(r => { remarkStr = remarkStr + spliter + r; }); } if (!string.IsNullOrEmpty(remarkStr)) { remarkStr = remarkStr.Substring(spliter.Length); } //生成报表 report.IndexValue = indexStr; report.InputDate = DateTime.Now; report.ReportType = type; report.ReportValue = dataStr; report.Remark = remarkStr; //添加报表 MesWeb.BLL.T_AllReport bllReport = new MesWeb.BLL.T_AllReport(); bllReport.Add(report); } } catch (Exception e) { return(false); } return(true); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(MesWeb.Model.T_AllReport model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_AllReport set "); strSql.Append("ReportValue=@ReportValue,"); strSql.Append("IndexValue=@IndexValue,"); strSql.Append("ReportType=@ReportType,"); strSql.Append("InputDate=@InputDate,"); strSql.Append("Remark=@Remark"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@ReportValue", SqlDbType.NVarChar, -1), new SqlParameter("@IndexValue", SqlDbType.NVarChar, -1), new SqlParameter("@ReportType", SqlDbType.NVarChar, -1), new SqlParameter("@InputDate", SqlDbType.DateTime), new SqlParameter("@Remark", SqlDbType.NVarChar, -1), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.ReportValue; parameters[1].Value = model.IndexValue; parameters[2].Value = model.ReportType; parameters[3].Value = model.InputDate; parameters[4].Value = model.Remark; parameters[5].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public MesWeb.Model.T_AllReport GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,ReportValue,IndexValue,ReportType,InputDate,Remark from T_AllReport "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; MesWeb.Model.T_AllReport model = new MesWeb.Model.T_AllReport(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }