Ejemplo n.º 1
0
 /// <summary>
 /// 主页面关闭事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     //太不友好?---选择机会---确认是否关闭   是--关闭; 否---不关闭
     //会出现两弹框??
     if (MsgBoxHelper.MsgBoxConfirm("关闭系统", "您确定要退出系统?") == DialogResult.Yes)
     {
         Application.ExitThread();//退出消息循环
     }
     else
     {
         e.Cancel = true;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 将DataGridView中数据导出到Excel
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="list"></param>
 /// <param name="dgv"></param>
 /// <param name="fileName"></param>
 /// <param name="sheetName"></param>
 /// <param name="msg"></param>
 /// <param name="title"></param>
 public static void DataToExcel <T>(List <T> list, DataGridViewColumnCollection cols, string fileName, string sheetName, string msg, string title)
 {
     if (list != null && list.Count > 0)
     {
         string filePath = "";
         FolderBrowserDialog fbdChoose = new FolderBrowserDialog();
         if (fbdChoose.ShowDialog() == DialogResult.OK)
         {
             filePath = fbdChoose.SelectedPath;
         }
         if (string.IsNullOrEmpty(filePath))
         {
             MsgBoxHelper.MsgErrorShow("请选择导出的位置!");
             return;
         }
         if (filePath.LastIndexOf('/') != filePath.Length - 1)
         {
             filePath += "/";
         }
         Dictionary <string, string> colsName = new Dictionary <string, string>();
         foreach (DataGridViewColumn dc in cols)
         {
             colsName.Add(dc.Name, dc.HeaderText);
         }
         int count = ExcelHelper.ListToExcel <T>(list, filePath + fileName, sheetName, colsName);
         if (count > 0)
         {
             MsgBoxHelper.MsgBoxShow(title, msg + "数据导出成功!");
         }
         else
         {
             MsgBoxHelper.MsgErrorShow(msg + "数据导出失败!");
         }
     }
     else
     {
         MsgBoxHelper.MsgErrorShow("没有数据可导出!");
         return;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 登录系统
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //接收信息
            string userName = txtUName.Text.Trim();
            string userPwd  = txtUPwd.Text.Trim();

            //判断是否为空
            if (string.IsNullOrEmpty(userName))
            {
                MsgBoxHelper.MsgErrorShow("账号不能为空!");
                txtUName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(userPwd))
            {
                MsgBoxHelper.MsgErrorShow("密码不能为空!");
                txtUPwd.Focus();
                return;
            }
            Action act = () =>
            {
                //加密
                string enPwd = MD5Encrypt.Encrypt(userPwd);

                List <ViewUserRoleModel> urList = RequestStar.Login(userName, enPwd); //登录
                                                                                      //判断结果
                if (urList == null || urList.Count == 0)
                {
                    MsgBoxHelper.MsgErrorShow("账号或密码输入有误,请检查!");
                    return;
                }
                else
                {
                    //转到主页面
                    if (!FormUtility.CheckOpenForm("FrmMain"))
                    {
                        FrmMain fMain = new FrmMain();
                        //登录页面显示处理---隐藏,不能关闭
                        fMain.Tag = new LoginModel()
                        {
                            URList    = urList,
                            LoginForm = this
                        };
                        fMain.Show();
                    }
                    else
                    {
                        //更换登录者时发生(暂留,后面实现)
                        //FormUtility.ShowOpenForm("FrmMain");
                        foreach (Form frm in Application.OpenForms)
                        {
                            if (frm.Name == "FrmMain")
                            {
                                frm.Tag = new LoginModel()
                                {
                                    URList    = urList,
                                    LoginForm = this
                                };
                                frm.Show();
                                break;
                            }
                        }
                    }
                    this.Hide();
                }
            };

            act.TryCatch("登录系统出现异常");
        }