using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsReportRangeSet; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using HcUtility.Comm; namespace DSWeb.MvcShipping.DAL.MsReportRangeSet { public class MsSysReportRangeDAL { #region Inquery DataList static public List GetUseReportList(string strCondition, string userid,string companyid,string sort = null) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("[GID],[RPTNAME],[RPTPROP],[ISDEFAULT],[COMPANYID]"); strSql.Append(",(SELECT COUNT(*) FROM sys_report_userrange WHERE RPTGID=sys_report.GID AND USERID='" + userid + "') as ISUSE "); strSql.Append(" from sys_report where companyid='" + companyid + "' "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring) && sortstring.Trim()!="") { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by RPTNAME"); } return SetData(strSql); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { SysReport data = new SysReport(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.RPTNAME = Convert.ToString(reader["RPTNAME"]); data.RPTPROP = Convert.ToString(reader["RPTPROP"]); data.ISDEFAULT = Convert.ToString(reader["ISDEFAULT"]); data.COMPANYID = Convert.ToString(reader["COMPANYID"]); if (reader["ISUSE"] != DBNull.Value) { if (Convert.ToInt32(reader["ISUSE"]) == 0) data.ISUSE = "可用"; else data.ISUSE = "不可用"; } else data.ISUSE = "可用"; #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion public static DBResult SetRptUseClick(List boday, string type, string userid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (boday != null) { var cmdDelete = db.GetSqlStringCommand("delete from sys_report_userrange where RPTGID=@RPTGID and USERID=@USERID "); foreach (var enumValue in boday) { if (type == "1") { var cmdInsert = db.GetSqlStringCommand("insert into sys_report_userrange(GID,USERID,RPTGID,RPTNAME,RPTPROP,COMPANYID) values(NEWID(),'" +userid+ "','"+enumValue.GID+"','"+enumValue.RPTNAME+"','" + enumValue.RPTNAME+ "','" +enumValue.COMPANYID+ "')"); db.ExecuteNonQuery(cmdInsert, tran); } else if (type == "2") { cmdDelete.Parameters.Clear(); db.AddInParameter(cmdDelete, "@RPTGID", DbType.String, enumValue.GID); db.AddInParameter(cmdDelete, "@USERID", DbType.String, userid); db.ExecuteNonQuery(cmdDelete, tran); } } } result = new DBResult(); result.Success = true; result.Message = "设置完成"; tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "设置完成出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "设置完成"; return result; } } }