Enterprise.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. namespace LYFZ.CloudServerData.DAL
  7. {
  8. public class Enterprise:BaseDataOperate<LYFZ.CloudServerData.Model.Enterprise>
  9. {
  10. public Enterprise(LYFZ.CloudServerData.Model.DBConnection dbConn)
  11. {
  12. base.DBConn = dbConn;
  13. }
  14. /// <summary>
  15. /// 获取新的企业ID
  16. /// </summary>
  17. /// <returns></returns>
  18. public static string GetNewEnterpriseID()
  19. {
  20. 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));
  21. }
  22. /// <summary>
  23. /// 验证企业基本信息
  24. /// </summary>
  25. /// <param name="enterpriseModel"></param>
  26. /// <param name="msg"></param>
  27. /// <returns></returns>
  28. public bool VerifyEnterpriseBaseInfo(LYFZ.CloudServerData.Model.Enterprise enterpriseModel, ref string msg)
  29. {
  30. if (String.IsNullOrEmpty(enterpriseModel.EnterpriseName))
  31. {
  32. msg = "企业名称不能为空";
  33. return false;
  34. }
  35. if (String.IsNullOrEmpty(enterpriseModel.EnterpriseID))
  36. {
  37. msg = "企业不能为空";
  38. return false;
  39. }
  40. if (enterpriseModel.EffectiveTime<=0)
  41. {
  42. msg = "有效期不能为空";
  43. return false;
  44. }
  45. return true;
  46. }
  47. /// <summary>
  48. /// 验证企业ID是否存在
  49. /// </summary>
  50. /// <param name="enterpriseID"></param>
  51. /// <param name="msg"></param>
  52. /// <returns></returns>
  53. public bool VerifyEnterpriseExists(string enterpriseID, ref string msg)
  54. {
  55. if (this.Exists("EnterpriseID", enterpriseID))
  56. {
  57. msg = "要添加的企业ID“" + enterpriseID + "”已经存在,不能重复添加";
  58. return false;
  59. }
  60. return true;
  61. }
  62. public LYFZ.CloudServerData.Model.CloudLoginInfo GetCloudLoginInfo(string enterpriseID)
  63. {
  64. List<System.Data.SqlClient.SqlParameter> parameterlist = new List<System.Data.SqlClient.SqlParameter>();
  65. parameterlist.Add(new System.Data.SqlClient.SqlParameter("@EnterpriseID", enterpriseID));
  66. System.Data.SqlClient.SqlParameter[] parameters = parameterlist.ToArray();
  67. 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;"
  68. + "SELECT [EnterpriseID],[StoreName],[DongleDomain] FROM [dbo].[tb_EnterpriseStore] where [EnterpriseID]=@EnterpriseID order by [IsHeadquarters]";
  69. DataSet dt= LYFZ.Helper.SQLHelper.Query(sql, this.DBConn.GetDBConnectionString(), parameters);
  70. DataTable tb=dt.Tables[0];
  71. if (tb.Rows.Count > 0)
  72. {
  73. Model.CloudLoginInfo loginInfo = new Model.CloudLoginInfo();
  74. loginInfo.EnterpriseID = tb.Rows[0]["EnterpriseID"].ToString();
  75. loginInfo.CloudServerID =Convert.ToInt64( tb.Rows[0]["CloudServerID"].ToString());
  76. loginInfo.CloudServerIP = tb.Rows[0]["DataBaseServerIP"].ToString();
  77. loginInfo.VerificationCode = tb.Rows[0]["InstallationCode"].ToString();
  78. loginInfo.SeverPort =Convert.ToUInt16(tb.Rows[0]["SeverPort"].ToString());
  79. DataTable tb2=dt.Tables[1];
  80. if (tb2.Rows.Count > 0)
  81. {
  82. foreach (DataRow row in tb2.Rows)
  83. {
  84. object DongleDomainList = new
  85. {
  86. StoreName = row["StoreName"].ToString(),
  87. DongleDomain = row["DongleDomain"].ToString(),
  88. };
  89. loginInfo.DongleDomainList.Add(DongleDomainList);
  90. }
  91. }
  92. return loginInfo;
  93. }
  94. else {
  95. return new Model.CloudLoginInfo();
  96. }
  97. }
  98. /// <summary>
  99. /// 验证企业是否正确
  100. /// </summary>
  101. /// <param name="eID"></param>
  102. /// <returns></returns>
  103. public static bool VerifyEnterpriseID(string eID)
  104. {
  105. if ("E6051908401744|E6051806481742|E6041618381744".ToLower().Contains(eID.ToLower()))
  106. {
  107. return true;
  108. }
  109. else
  110. {
  111. if (eID.ToLower().IndexOf("e") == 0 && eID.Length == 18)
  112. {
  113. return true;
  114. }
  115. else
  116. {
  117. return false;
  118. }
  119. }
  120. }
  121. /// <summary>
  122. /// 更新WebUrl
  123. /// </summary>
  124. /// <param name="enterpriseid"></param>
  125. /// <param name="webUrl"></param>
  126. /// <returns></returns>
  127. public bool UpdateWebInterfaceAddress(string enterpriseid, string webUrl)
  128. {
  129. string sql = " update [dbo].[tb_Enterprise] set WebInterfaceAddress='" + webUrl + "' where [EnterpriseID]='" + enterpriseid + "'";
  130. if (LYFZ.Helper.SQLHelper.ExecuteSql(sql, this.DBConn.GetDBConnectionString()) > 0)
  131. {
  132. return true;
  133. }
  134. else
  135. {
  136. return false;
  137. }
  138. }
  139. public DataTable GetEnterpriseData(string searchText,string serviceText,bool bCloud,
  140. int pageIndx,int pageSize)
  141. {
  142. string sql = @" SELECT distinct [tb_Enterprise].*,[tb_CloudServerCollection].[CloudServerName]
  143. FROM [tb_Enterprise] inner join [tb_CloudServerCollection] on [tb_CloudServerCollection].[ID]=[tb_Enterprise].CloudServerID
  144. left join tb_EnterpriseStore on tb_EnterpriseStore.EnterpriseID=[tb_Enterprise].EnterpriseID ";
  145. string strWhere = "";
  146. if (!string.IsNullOrEmpty(searchText))
  147. {
  148. if (!string.IsNullOrEmpty(strWhere))
  149. {
  150. strWhere += " and ";
  151. }
  152. strWhere += " (tb_Enterprise.EnterpriseID like '%" + searchText + "%' or tb_Enterprise.EnterpriseName like '%" + searchText + "%' or tb_Enterprise.ContactPerson like '%" + searchText + "%' " +
  153. " or tb_Enterprise.Phone like '%" + searchText + "%' or tb_EnterpriseStore.StoreAddress like '%" + searchText + "%' "
  154. + " ) ";
  155. }
  156. if (!string.IsNullOrEmpty(serviceText))
  157. {
  158. if (!string.IsNullOrEmpty(strWhere))
  159. {
  160. strWhere += " and ";
  161. }
  162. strWhere += " ( CloudServerID like '%" + serviceText + "%' ) ";
  163. }
  164. if (bCloud)
  165. {
  166. if (!string.IsNullOrEmpty(strWhere))
  167. {
  168. strWhere += " and ";
  169. }
  170. strWhere += " ( tb_Enterprise.Features like '%{\"name\":\"托管数据库\",\"value\":1}%' ) ";
  171. }
  172. if(!string.IsNullOrEmpty(strWhere))
  173. {
  174. sql += " where " + strWhere;
  175. }
  176. DataTable dt = LYFZ.Helper.SQLHelper.Query(sql, this.DBConn.GetDBConnectionString()).Tables[0];
  177. DataTable jsonDt = dt.AsEnumerable().Skip((pageIndx - 1) * pageSize).Take(pageSize).CopyToDataTable();
  178. return jsonDt;
  179. }
  180. }
  181. }