You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/DAL/MsHome/MsHomeDAL.cs

209 lines
9.2 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsMainForm;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
namespace DSWeb.MvcShipping.DAL.MsHome
{
public class MsHomeDAL
{
public static List<UserMainmoduleSet> GetColourStyle(string userid)
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("select distinct COLOURSTYLE from main_module where COMPANYID=(select COMPANYID from user_company where USERID='" + userid + "')");
return SetColourStyle(sql);
}
public static List<UserMainmoduleSet> SetColourStyle(StringBuilder sql)
{
var headList = new List<UserMainmoduleSet>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString()))
{
while (reader.Read())
{
UserMainmoduleSet data = new UserMainmoduleSet();
#region Set DB data to Object
data.COLOURSTYLE = Convert.ToInt16(reader["COLOURSTYLE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult SetDialogVisible(string id)
{
bool chkVal = false;
Database db = DatabaseFactory.CreateDatabase();
var result = new DBResult();
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT ISVISIABLE ");
sql.AppendLine("FROM user_mainmd_set ");
sql.AppendLine("WHERE MODULEID='" + id + "'");
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString()))
{
while (reader.Read())
{
chkVal = Convert.ToBoolean(reader["ISVISIABLE"]);
}
}
chkVal = !chkVal;
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
string cmdUpdateStr = "update user_mainmd_set set ISVISIABLE='" + chkVal + "' where MODULEID='" + id + "'";
var cmdUpdate = db.GetSqlStringCommand(cmdUpdateStr);
db.ExecuteNonQuery(cmdUpdate, tran);
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
static public List<UserMainmoduleSet> GetDataList(string userid, string companyid)
{
var strSql = new StringBuilder();
strSql.AppendLine("select B.ITEMID,A.MODULEWIDTH,A.MODULEHEIGHT,A.MODULELEFT,A.MODULETOP,A.ISVISIABLE, ");
strSql.AppendLine("(select MODULENAME from main_module where GID=A.MODULEID and ISUSE=1) as MODULENAME, ");
strSql.AppendLine("(select MODULETITLE from main_module where GID=A.MODULEID and ISUSE=1) as MODULETITLE, ");
strSql.AppendLine("(select MODULEURL from main_module where GID=A.MODULEID and ISUSE=1) as MODULEURL, ");
strSql.AppendLine("(select MODULEWIDTH from main_module where GID=A.MODULEID and ISUSE=1) as DEFAULTWIDTH, ");
strSql.AppendLine("(select MODULEHEIGHT from main_module where GID=A.MODULEID and ISUSE=1) as DEFAULTHEIGHT, ");
strSql.AppendLine("(select USERTEMPLETID from main_module where GID=A.MODULEID and ISUSE=1) as USERTEMPLETID, ");
strSql.AppendLine("(select GID from main_module where GID=A.MODULEID and ISUSE=1) as GID ");
strSql.AppendLine("from user_mainmd_set as A ");
strSql.AppendLine("left join templet as B on A.MODULEID=B.PARENTITEMID ");
strSql.AppendLine("left join main_module as C on A.MODULEID=C.GID ");
strSql.AppendLine("where A.USERID='" + userid + "' and C.COMPANYID='" + companyid + "' ");//");
strSql.AppendLine("order by A.SORT asc");
return SetDataList(strSql);
}
private static List<UserMainmoduleSet> SetDataList(StringBuilder strSql)
{
var headList = new List<UserMainmoduleSet>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
UserMainmoduleSet data = new UserMainmoduleSet();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.ITEMID = Convert.ToString(reader["ITEMID"]);
data.MODULENAME = Convert.ToString(reader["MODULENAME"]);
data.MODULETITLE = Convert.ToString(reader["MODULETITLE"]);
data.MODULEURL = Convert.ToString(reader["MODULEURL"]);
data.USERTEMPLETID = Convert.ToString(reader["USERTEMPLETID"]);
if (reader["MODULETOP"] != DBNull.Value)
data.MODULETOP = Convert.ToInt16(reader["MODULETOP"]);
if (reader["MODULELEFT"] != DBNull.Value)
data.MODULELEFT = Convert.ToInt16(reader["MODULELEFT"]);
if (reader["MODULEWIDTH"] != DBNull.Value)
data.MODULEWIDTH = Convert.ToInt16(reader["MODULEWIDTH"]);
if (reader["MODULEHEIGHT"] != DBNull.Value)
data.MODULEHEIGHT = Convert.ToInt16(reader["MODULEHEIGHT"]);
if (reader["DEFAULTWIDTH"] != DBNull.Value)
data.DEFAULTMODULEWIDTH = Convert.ToInt16(reader["DEFAULTWIDTH"]);
if (reader["DEFAULTHEIGHT"] != DBNull.Value)
data.DEFAULTMODULEHEIGHT = Convert.ToInt16(reader["DEFAULTHEIGHT"]);
if (reader["ISVISIABLE"] != DBNull.Value)
data.ISVISIABLE = Convert.ToBoolean(reader["ISVISIABLE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#region 设置模板位置
public static DBResult SetLoacation(string gid, string userid, string x, string y, string width, string height)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdModify = db.GetSqlStringCommand(@"update user_mainmd_set set MODULELEFT='" + x + "',MODULETOP='" + y + "',MODULEWIDTH='" + width + "',MODULEHEIGHT='" + height + "',MODIFIEDTIME='" + DateTime.Now.ToString() + "',MODIFIEDUSER='" + userid + "' where MODULEID='" + gid + "' and USERID='" + userid + "'");
db.ExecuteNonQuery(cmdModify, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
#region 设置模板大小
public static DBResult SetSize(string gid, string userid, string width, string height)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdModify = db.GetSqlStringCommand(@"update user_mainmd_set set MODULEWIDTH='" + width + "',MODULEHEIGHT='" + height + "',MODIFIEDTIME='" + DateTime.Now.ToString() + "',MODIFIEDUSER='" + userid + "' where MODULEID='" + gid + "' and USERID='" + userid + "'");
db.ExecuteNonQuery(cmdModify, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#endregion
}
}