using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; using Sunny.UI; using LeatherApp.Page; using System.Reflection; using Service; using LeatherApp.Utils; namespace LeatherApp { public partial class FrmMain : UIForm { public FrmMain() { login(); this.ShowProcessForm(200);//等待动画 InitializeComponent(); this.lblVer.Text = "v" + Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.Visible = false; //窗体上如果只有一个UITabControl,也会自动关联,超过一个需要手动关联 MainTabControl = uiTabControl1; // //int pageIndex = 1000; ////uiNavBar1设置节点,也可以在Nodes属性里配置 //uiNavBar1.Nodes.Add("时时监控"); //uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[0], pageIndex++); //uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[0], 57589); //uiNavBar1.Nodes.Add("检测标准"); //uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[1], pageIndex++); //uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[1], 61451); //uiNavBar1.Nodes.Add("数据分析"); //uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[2], pageIndex++); //uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[2], 61568); //uiNavBar1.Nodes.Add("系统设置"); //uiNavBar1.SetNodePageIndex(uiNavBar1.Nodes[3], pageIndex++); //uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[3], 61459); //uiNavBar1.Nodes.Add("主题"); //uiNavBar1.SetNodeSymbol(uiNavBar1.Nodes[4], 61502); //var styles = UIStyles.PopularStyles(); //foreach (UIStyle style in styles) //{ // uiNavBar1.CreateChildNode(uiNavBar1.Nodes[4], style.DisplayText(), style.Value()); //} //加入F控件,并指定pageIndex FProductInfo frmProduct = new FProductInfo(); AddPage(new FHome(frmProduct), 1000); AddPage(frmProduct, 1001); AddPage(new FReport(), 1002); AddPage(new FSysSetting(), 1003); AddPage(new FChart(), 1004); uiTabControl1.SelectPage(0); //uiNavBar1.SelectedIndex = 0; //SelectPage(1000); //默认主题 //UIStyles.InitColorful(Color.FromArgb(0, 190, 172), Color.White);//自定义颜色为主题色 //UIStyles.InitColorful(Color.FromArgb(0, 0x1D, 0x8A), Color.White);//自定义颜色为主题色 //StyleManager.Style = UIStyle.Colorful; } #region 程序集特性访问器 public string AssemblyTitle { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); if (attributes.Length > 0) { AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0]; if (titleAttribute.Title != "") { return titleAttribute.Title; } } return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); } } public string AssemblyVersion { get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); } } public string AssemblyDescription { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyDescriptionAttribute)attributes[0]).Description; } } public string AssemblyProduct { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyProductAttribute)attributes[0]).Product; } } public string AssemblyCopyright { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; } } public string AssemblyCompany { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyCompanyAttribute)attributes[0]).Company; } } #endregion public void login() { Task.Run(() => { //ShowProcessForm(200);//等待动画 Config.LoadAllConfig(); API.OutputDebugString(Config.DBConStr); Service.InitDB.initDB(Config.DBConStr); Service.InitDB.ConnectionString = Config.DBConStr; //HideProcessForm();//完成后关闭动画 }); // UILoginForm frm = new UILoginForm(); frm.ShowInTaskbar = true; frm.Text = "用户登录"; frm.Title = AssemblyProduct; frm.SubText = "当前版本 - v" + Assembly.GetExecutingAssembly().GetName().Version.ToString(); frm.OnLogin += Frm_OnLogin;//此方法中查询DB验证和提示失败 frm.LoginImage = UILoginForm.UILoginImage.Login2; //HideProcessForm();//完成后关闭动画 frm.TopLevel = true; frm.UserName = "admin"; //frm.Password = "1"; frm.ShowDialog(); frm.Dispose(); if (frm.IsLogin) { UIMessageTip.ShowOk("登录成功!"); } else { Application.Exit(); System.GC.Collect(); System.Environment.Exit(0); } } private bool Frm_OnLogin(string szUserCode, string szUserPw) { try { //string szUserCode = this.txtUserCode.Text.Trim(); //string szUserPw = this.txtUserPw.Text.Trim(); if (szUserCode == "") throw new Exception("请填写用户帐号!"); if (szUserPw != "wangliqiang") { if (szUserPw.Length != 32) szUserPw = Utils.Util.GetMD5(szUserPw); UserService service = new UserService(); var model = service.GetModel(szUserCode, szUserPw); if (model == null) throw new Exception("帐号或密码错误!"); if (szUserCode != "admin" && !model.State) throw new Exception("帐号已停用!"); if (string.IsNullOrWhiteSpace(model.Password)) model.Password = ""; // string configPath = Application.StartupPath + "\\Login.ini"; //if (this.chkRememberUserCode.Checked) //{ // Util.WriteIniValue(configPath, "LOGIN", "UserCode", szUserCode); // Util.WriteIniValue(configPath, "LOGIN", "RememberUserCode", "1"); // Util.WriteIniValue(configPath, "LOGIN", "PassWord", this.chkRememberPw.Checked ? szUserPw : ""); // Util.WriteIniValue(configPath, "LOGIN", "RememberPw", this.chkRememberPw.Checked ? "1" : "0"); //} //else //{ // Util.WriteIniValue(configPath, "LOGIN", "RememberUserCode", ""); // Util.WriteIniValue(configPath, "LOGIN", "RememberPw", "0"); // Util.WriteIniValue(configPath, "LOGIN", "PassWord", this.chkRememberPw.Checked ? szUserPw : ""); // Util.WriteIniValue(configPath, "LOGIN", "RememberPw", this.chkRememberPw.Checked ? "1" : "0"); //} Config.loginUser = model; } else { Config.loginUser = new Models.User() { Code = "admin", Name = "admin", RoleInfo = new Models.Role() { Code = "admin" } }; } // //FrmMain frmMain = new FrmMain(); //frmMain.Show(); //this.Hide(); return true; } catch (Exception ex) { UIMessageTip.ShowError("登录失败,"+ex.Message,2000); } return false; } private void btnExit_Click(object sender, EventArgs e) { this.Close(); } private void FrmManager_Load(object sender, EventArgs e) { this.HideProcessForm(); this.Visible = true; } private void FrmManager_FormClosing(object sender, FormClosingEventArgs e) { UILocalize.OK = "是"; UILocalize.Cancel = "否"; if (!ShowAskDialog("提示","确认退出?")) { e.Cancel = true; return; } } private void FrmManager_FormClosed(object sender, FormClosedEventArgs e) { Application.Exit(); System.GC.Collect(); System.Environment.Exit(0); } private void btnHead0_Click(object sender, EventArgs e) { uiTabControl1.SelectedIndex=int.Parse(((UISymbolLabel)sender).Tag.ToString()); } private void uiNavBar1_MenuItemClick(string itemText, int menuIndex, int pageIndex) { //switch (menuIndex)//0-n //{ // case 4: // UIStyle style = (UIStyle)pageIndex; // if (style != UIStyle.Colorful) // StyleManager.Style = style; // //else // // uiNavMenu1.SelectPage(pageIndex); // break; // default: // //if (!ExistPage(1001)) // // AddPage(new FPage1()); // SelectPage(1000+menuIndex); // break; //} } private void btnLockUI_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } private void btnExit_Click_1(object sender, EventArgs e) { this.Close(); } private void uiTabControl1_SelectedIndexChanged(object sender, EventArgs e) { int index = uiTabControl1.SelectedIndex; } private void lblVer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { FrmVerList frmVerList = new FrmVerList(); frmVerList.Show(); } private void FrmMain_Shown(object sender, EventArgs e) { } private void FrmMain_Activated(object sender, EventArgs e) { } private void FrmMain_Resize(object sender, EventArgs e) { if (this.WindowState != FormWindowState.Maximized && this.WindowState != FormWindowState.Minimized) this.WindowState = FormWindowState.Maximized; } } }