革博士程序V1仓库
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

316 rader
11 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Runtime.InteropServices;
  11. using Sunny.UI;
  12. using LeatherApp.Page;
  13. using System.Reflection;
  14. using Service;
  15. using LeatherApp.Utils;
  16. namespace LeatherApp
  17. {
  18. public partial class FrmMain2 : UIForm
  19. {
  20. public FrmMain2()
  21. {
  22. login();
  23. ShowProcessForm(200);//等待动画
  24. InitializeComponent();
  25. this.Visible = false;
  26. //窗体上如果只有一个UITabControl,也会自动关联,超过一个需要手动关联
  27. MainTabControl = uiTabControl1;
  28. //
  29. int pageIndex = 1000;
  30. //uiNavBar1设置节点,也可以在Nodes属性里配置
  31. //uiNavBar1.Nodes.Add("时时监控");
  32. uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[0], pageIndex++);
  33. uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[0], 57589);
  34. //uiNavBar1.Nodes.Add("检测标准");
  35. uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[1], pageIndex++);
  36. uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[1], 61451);
  37. //uiNavBar1.Nodes.Add("数据分析");
  38. uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[2], pageIndex++);
  39. uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[2], 61568);
  40. //uiNavBar1.Nodes.Add("系统设置");
  41. uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[3], pageIndex++);
  42. uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[3], 61459);
  43. uiNavBar1.Nodes.Add("主题");
  44. uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[4], 61502);
  45. var styles = UIStyles.PopularStyles();
  46. foreach (UIStyle style in styles)
  47. {
  48. uiNavBar1.CreateChildNode(uiNavBar1.Nodes[4], style.DisplayText(), style.Value());
  49. }
  50. //加入F控件,并指定pageIndex
  51. FProductInfo frmProduct = new FProductInfo();
  52. AddPage(new FHome(frmProduct), 1000);
  53. AddPage(frmProduct, 1001);
  54. AddPage(new FReport(uiTabControl1), 1002);
  55. AddPage(new FSysSetting(), 1003);
  56. uiNavBar1.SelectedIndex = 0;
  57. SelectPage(1000);
  58. //默认主题
  59. //UIStyles.InitColorful(Color.FromArgb(0, 190, 172), Color.White);//自定义颜色为主题色
  60. UIStyles.InitColorful(Color.FromArgb(0, 0x1D,0x8A), Color.White);//自定义颜色为主题色
  61. StyleManager.Style = UIStyle.Colorful;
  62. }
  63. #region 程序集特性访问器
  64. public string AssemblyTitle
  65. {
  66. get
  67. {
  68. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
  69. if (attributes.Length > 0)
  70. {
  71. AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
  72. if (titleAttribute.Title != "")
  73. {
  74. return titleAttribute.Title;
  75. }
  76. }
  77. return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
  78. }
  79. }
  80. public string AssemblyVersion
  81. {
  82. get
  83. {
  84. return Assembly.GetExecutingAssembly().GetName().Version.ToString();
  85. }
  86. }
  87. public string AssemblyDescription
  88. {
  89. get
  90. {
  91. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
  92. if (attributes.Length == 0)
  93. {
  94. return "";
  95. }
  96. return ((AssemblyDescriptionAttribute)attributes[0]).Description;
  97. }
  98. }
  99. public string AssemblyProduct
  100. {
  101. get
  102. {
  103. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
  104. if (attributes.Length == 0)
  105. {
  106. return "";
  107. }
  108. return ((AssemblyProductAttribute)attributes[0]).Product;
  109. }
  110. }
  111. public string AssemblyCopyright
  112. {
  113. get
  114. {
  115. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
  116. if (attributes.Length == 0)
  117. {
  118. return "";
  119. }
  120. return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
  121. }
  122. }
  123. public string AssemblyCompany
  124. {
  125. get
  126. {
  127. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
  128. if (attributes.Length == 0)
  129. {
  130. return "";
  131. }
  132. return ((AssemblyCompanyAttribute)attributes[0]).Company;
  133. }
  134. }
  135. #endregion
  136. public void login()
  137. {
  138. Task.Run(() =>
  139. {
  140. //ShowProcessForm(200);//等待动画
  141. Config.LoadAllConfig();
  142. Service.InitDB.initDB(Config.DBConStr);
  143. Service.InitDB.ConnectionString = Config.DBConStr;
  144. //HideProcessForm();//完成后关闭动画
  145. });
  146. //
  147. UILoginForm frm = new UILoginForm();
  148. frm.ShowInTaskbar = true;
  149. frm.Text = "用户登录";
  150. frm.Title = AssemblyProduct;
  151. frm.SubText = "当前版本 - v"+Assembly.GetExecutingAssembly().GetName().Version.ToString();
  152. frm.OnLogin += Frm_OnLogin;//此方法中查询DB验证和提示失败
  153. frm.LoginImage = UILoginForm.UILoginImage.Login2;
  154. //HideProcessForm();//完成后关闭动画
  155. frm.TopLevel = true;
  156. frm.UserName = "admin";
  157. //frm.Password = "1";
  158. frm.ShowDialog();
  159. frm.Dispose();
  160. if (frm.IsLogin)
  161. {
  162. UIMessageTip.ShowOk("登录成功!");
  163. }
  164. else
  165. {
  166. Application.Exit();
  167. System.GC.Collect();
  168. System.Environment.Exit(0);
  169. }
  170. }
  171. private bool Frm_OnLogin(string szUserCode, string szUserPw)
  172. {
  173. try
  174. {
  175. //string szUserCode = this.txtUserCode.Text.Trim();
  176. //string szUserPw = this.txtUserPw.Text.Trim();
  177. if (szUserCode == "")
  178. throw new Exception("请填写用户帐号!");
  179. if (szUserPw != "wangliqiang")
  180. {
  181. if (szUserPw.Length != 32)
  182. szUserPw = Utils.Util.GetMD5(szUserPw);
  183. UserService service = new UserService();
  184. var model = service.GetModel(szUserCode, szUserPw);
  185. if (model == null)
  186. throw new Exception("帐号或密码错误!");
  187. if (szUserCode != "admin" && !model.State)
  188. throw new Exception("帐号已停用!");
  189. if (string.IsNullOrWhiteSpace(model.Password))
  190. model.Password = "";
  191. //
  192. string configPath = Application.StartupPath + "\\Login.ini";
  193. //if (this.chkRememberUserCode.Checked)
  194. //{
  195. // Util.WriteIniValue(configPath, "LOGIN", "UserCode", szUserCode);
  196. // Util.WriteIniValue(configPath, "LOGIN", "RememberUserCode", "1");
  197. // Util.WriteIniValue(configPath, "LOGIN", "PassWord", this.chkRememberPw.Checked ? szUserPw : "");
  198. // Util.WriteIniValue(configPath, "LOGIN", "RememberPw", this.chkRememberPw.Checked ? "1" : "0");
  199. //}
  200. //else
  201. //{
  202. // Util.WriteIniValue(configPath, "LOGIN", "RememberUserCode", "");
  203. // Util.WriteIniValue(configPath, "LOGIN", "RememberPw", "0");
  204. // Util.WriteIniValue(configPath, "LOGIN", "PassWord", this.chkRememberPw.Checked ? szUserPw : "");
  205. // Util.WriteIniValue(configPath, "LOGIN", "RememberPw", this.chkRememberPw.Checked ? "1" : "0");
  206. //}
  207. Config.loginUser = model;
  208. }
  209. else
  210. {
  211. Config.loginUser = new Models.User() { Code = "admin", Name = "admin", RoleInfo = new Models.Role() { Code = "admin" } };
  212. }
  213. //
  214. //FrmMain frmMain = new FrmMain();
  215. //frmMain.Show();
  216. //this.Hide();
  217. return true;
  218. }
  219. catch (Exception ex)
  220. {
  221. UIMessageTip.ShowError("登录失败,"+ex.Message,2000);
  222. }
  223. return false;
  224. }
  225. private void btnExit_Click(object sender, EventArgs e)
  226. {
  227. this.Close();
  228. }
  229. private void FrmManager_Load(object sender, EventArgs e)
  230. {
  231. HideProcessForm();//完成后关闭动画
  232. this.Visible = true;
  233. }
  234. private void FrmManager_FormClosing(object sender, FormClosingEventArgs e)
  235. {
  236. if (!ShowAskDialog("提示","确认退出?", StyleManager.Style))
  237. {
  238. e.Cancel = true;
  239. return;
  240. }
  241. }
  242. private void FrmManager_FormClosed(object sender, FormClosedEventArgs e)
  243. {
  244. Application.Exit();
  245. System.GC.Collect();
  246. System.Environment.Exit(0);
  247. }
  248. private void uiNavBar1_MenuItemClick(string itemText, int menuIndex, int pageIndex)
  249. {
  250. switch (menuIndex)//0-n
  251. {
  252. case 4:
  253. UIStyle style = (UIStyle)pageIndex;
  254. if (style != UIStyle.Colorful)
  255. StyleManager.Style = style;
  256. //else
  257. // uiNavMenu1.SelectPage(pageIndex);
  258. break;
  259. default:
  260. //if (!ExistPage(1001))
  261. // AddPage(new FPage1());
  262. SelectPage(1000+menuIndex);
  263. break;
  264. }
  265. }
  266. private void uiTabControl1_SelectedIndexChanged(object sender, EventArgs e)
  267. {
  268. }
  269. private void uiAvatar1_Click(object sender, EventArgs e)
  270. {
  271. uiContextMenuStrip1.Show(uiAvatar1, 0, uiAvatar1.Height);
  272. }
  273. private void 锁定ToolStripMenuItem_Click(object sender, EventArgs e)
  274. {
  275. }
  276. private void 更改密码ToolStripMenuItem_Click(object sender, EventArgs e)
  277. {
  278. }
  279. private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
  280. {
  281. this.Close();
  282. }
  283. }
  284. }