123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- namespace LYFZ.CloudServerData.DAL
- {
- public class Enterprise:BaseDataOperate<LYFZ.CloudServerData.Model.Enterprise>
- {
- public Enterprise(LYFZ.CloudServerData.Model.DBConnection dbConn)
- {
- base.DBConn = dbConn;
- }
- /// <summary>
- /// 获取新的企业ID
- /// </summary>
- /// <returns></returns>
- public static string GetNewEnterpriseID()
- {
- return String.Format("E{0}{1}{2}", new Random(SDateTime.Now.Second).Next(10,99),SDateTime.Now.ToString("MMHHddmmyyss"), new Random(SDateTime.Now.Second).Next(100,999));
- }
- /// <summary>
- /// 验证企业基本信息
- /// </summary>
- /// <param name="enterpriseModel"></param>
- /// <param name="msg"></param>
- /// <returns></returns>
- public bool VerifyEnterpriseBaseInfo(LYFZ.CloudServerData.Model.Enterprise enterpriseModel, ref string msg)
- {
- if (String.IsNullOrEmpty(enterpriseModel.EnterpriseName))
- {
- msg = "企业名称不能为空";
- return false;
- }
- if (String.IsNullOrEmpty(enterpriseModel.EnterpriseID))
- {
- msg = "企业不能为空";
- return false;
- }
- if (enterpriseModel.EffectiveTime<=0)
- {
- msg = "有效期不能为空";
- return false;
- }
- return true;
- }
- /// <summary>
- /// 验证企业ID是否存在
- /// </summary>
- /// <param name="enterpriseID"></param>
- /// <param name="msg"></param>
- /// <returns></returns>
- public bool VerifyEnterpriseExists(string enterpriseID, ref string msg)
- {
- if (this.Exists("EnterpriseID", enterpriseID))
- {
- msg = "要添加的企业ID“" + enterpriseID + "”已经存在,不能重复添加";
- return false;
- }
- return true;
- }
- public LYFZ.CloudServerData.Model.CloudLoginInfo GetCloudLoginInfo(string enterpriseID)
- {
- List<System.Data.SqlClient.SqlParameter> parameterlist = new List<System.Data.SqlClient.SqlParameter>();
- parameterlist.Add(new System.Data.SqlClient.SqlParameter("@EnterpriseID", enterpriseID));
- System.Data.SqlClient.SqlParameter[] parameters = parameterlist.ToArray();
- string sql = "SELECT [EnterpriseID],[CloudServerID],[DataBaseServerIP],[InstallationCode],[SeverPort] FROM [dbo].[tb_Enterprise] left join dbo.tb_CloudServerCollection on [CloudServerID]=dbo.tb_CloudServerCollection.id where [CloudServerID]>0 and [EnterpriseID]=@EnterpriseID;"
- + "SELECT [EnterpriseID],[StoreName],[DongleDomain] FROM [dbo].[tb_EnterpriseStore] where [EnterpriseID]=@EnterpriseID order by [IsHeadquarters]";
- DataSet dt= LYFZ.Helper.SQLHelper.Query(sql, this.DBConn.GetDBConnectionString(), parameters);
- DataTable tb=dt.Tables[0];
- if (tb.Rows.Count > 0)
- {
- Model.CloudLoginInfo loginInfo = new Model.CloudLoginInfo();
- loginInfo.EnterpriseID = tb.Rows[0]["EnterpriseID"].ToString();
- loginInfo.CloudServerID =Convert.ToInt64( tb.Rows[0]["CloudServerID"].ToString());
- loginInfo.CloudServerIP = tb.Rows[0]["DataBaseServerIP"].ToString();
- loginInfo.VerificationCode = tb.Rows[0]["InstallationCode"].ToString();
- loginInfo.SeverPort =Convert.ToUInt16(tb.Rows[0]["SeverPort"].ToString());
- DataTable tb2=dt.Tables[1];
- if (tb2.Rows.Count > 0)
- {
- foreach (DataRow row in tb2.Rows)
- {
- object DongleDomainList = new
- {
- StoreName = row["StoreName"].ToString(),
- DongleDomain = row["DongleDomain"].ToString(),
- };
- loginInfo.DongleDomainList.Add(DongleDomainList);
- }
- }
- return loginInfo;
- }
- else {
- return new Model.CloudLoginInfo();
- }
- }
- /// <summary>
- /// 验证企业是否正确
- /// </summary>
- /// <param name="eID"></param>
- /// <returns></returns>
- public static bool VerifyEnterpriseID(string eID)
- {
- if ("E6051908401744|E6051806481742|E6041618381744".ToLower().Contains(eID.ToLower()))
- {
- return true;
- }
- else
- {
- if (eID.ToLower().IndexOf("e") == 0 && eID.Length == 18)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- /// <summary>
- /// 更新WebUrl
- /// </summary>
- /// <param name="enterpriseid"></param>
- /// <param name="webUrl"></param>
- /// <returns></returns>
- public bool UpdateWebInterfaceAddress(string enterpriseid, string webUrl)
- {
- string sql = " update [dbo].[tb_Enterprise] set WebInterfaceAddress='" + webUrl + "' where [EnterpriseID]='" + enterpriseid + "'";
- if (LYFZ.Helper.SQLHelper.ExecuteSql(sql, this.DBConn.GetDBConnectionString()) > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- public DataTable GetEnterpriseData(string searchText,string serviceText,bool bCloud,
- int pageIndx,int pageSize)
- {
- string sql = @" SELECT distinct [tb_Enterprise].*,[tb_CloudServerCollection].[CloudServerName]
- FROM [tb_Enterprise] inner join [tb_CloudServerCollection] on [tb_CloudServerCollection].[ID]=[tb_Enterprise].CloudServerID
- left join tb_EnterpriseStore on tb_EnterpriseStore.EnterpriseID=[tb_Enterprise].EnterpriseID ";
- string strWhere = "";
- if (!string.IsNullOrEmpty(searchText))
- {
- if (!string.IsNullOrEmpty(strWhere))
- {
- strWhere += " and ";
- }
- strWhere += " (tb_Enterprise.EnterpriseID like '%" + searchText + "%' or tb_Enterprise.EnterpriseName like '%" + searchText + "%' or tb_Enterprise.ContactPerson like '%" + searchText + "%' " +
- " or tb_Enterprise.Phone like '%" + searchText + "%' or tb_EnterpriseStore.StoreAddress like '%" + searchText + "%' "
- + " ) ";
- }
- if (!string.IsNullOrEmpty(serviceText))
- {
- if (!string.IsNullOrEmpty(strWhere))
- {
- strWhere += " and ";
- }
- strWhere += " ( CloudServerID like '%" + serviceText + "%' ) ";
- }
- if (bCloud)
- {
- if (!string.IsNullOrEmpty(strWhere))
- {
- strWhere += " and ";
- }
- strWhere += " ( tb_Enterprise.Features like '%{\"name\":\"托管数据库\",\"value\":1}%' ) ";
- }
- if(!string.IsNullOrEmpty(strWhere))
- {
- sql += " where " + strWhere;
- }
-
- DataTable dt = LYFZ.Helper.SQLHelper.Query(sql, this.DBConn.GetDBConnectionString()).Tables[0];
- DataTable jsonDt = dt.AsEnumerable().Skip((pageIndx - 1) * pageSize).Take(pageSize).CopyToDataTable();
- return jsonDt;
- }
- }
- }
|