Example #1
0
        private void btnSave1_Click(object sender, EventArgs e)
        {
            string ConnStr = null;

            //ConnStr = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}", txtAccess.Text);
            ConnStr = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;Jet OLEDB:Database Password=meiyoumima2011", txtAccess.Text);

            try
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration("PubClasses.dll");

                config.ConnectionStrings.ConnectionStrings.Remove("PubClasses.Properties.Settings.Setting_ConnStr");
                config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("PubClasses.Properties.Settings.Setting_ConnStr", ConnStr, "System.Data.OleDb"));
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("ConnectionStrings");
                // My.Settings.ConnectionString = config.ConnectionStrings.ConnectionStrings("一卡通.Properties.Settings.Default.ConnectionString").ToString
                //MsgBox(My.Settings.ConnectionString)
                Dlg.ShowOKInfo("保存成功,程序将重新启动");
                Application.Exit();
                System.Diagnostics.Process.Start(Application.ExecutablePath.ToString());
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(ex.Message.ToString());
            }
        }
Example #2
0
        private void btnAudit_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("确认复核通过?", "提示", MessageBoxButtons.YesNo))
            {
                int    ret         = 0;
                string auditString = "";
                foreach (DataGridViewRow mRow in dgvNoTicketAudit.Rows)
                {
                    if (Convert.ToBoolean(mRow.Cells["ColumnChecked"].Value) == true)
                    {
                        auditString += mRow.Cells["idDataGridViewTextBoxColumn"].Value + ",";
                    }
                }
                auditString = auditString.TrimEnd(',');

                if (auditString == "")
                {
                    Dlg.ShowErrorInfoAndHelp("没有选择要复核的记录");
                    return;
                }

                string mSql = string.Format("UPDATE T_NoTicket SET P2 = '{0}',P3 = '{1}', AuditDate = GETDATE()  WHERE Id IN ({2})", "复核已通过", Classes.PubClass.UserId, auditString);
                ret = SqlHelper.ExecuteNonQuery(mSql);
                if (ret > 0)
                {
                    Dlg.ShowOKInfo("保存成功");
                    //刷新页面
                    refresh();
                }
                else
                {
                    Dlg.ShowErrorInfo("保存失败");
                }
            }
        }
Example #3
0
 public static bool ConnectDB(string connStr)
 {
     try
     {
         using (OleDbConnection mConn = new OleDbConnection(connStr))
         {
             mConn.Open();
             if (mConn.Provider.IndexOf("SQLOLEDB") != -1)
             {
                 CommonClass.SttDb.iDBType = 1;
             }
             else if (mConn.Provider.IndexOf("Jet") != -1)
             {
                 CommonClass.SttDb.iDBType = 0;
             }
             else
             {
                 CommonClass.SttDb.iDBType = -2;
             }
             CommonClass.SttDb.sDbInfo     = string.Format("{0}({1})", mConn.DataSource, mConn.Database);
             CommonClass.SttDb.sDataSource = mConn.DataSource;
             mConn.Close();
             return(false);
         }
     }
     catch (Exception ex)
     {
         Dlg.ShowErrorInfo(ex.Message);
         return(true);
     }
 }
Example #4
0
 private void tsbModify_Click(object sender, EventArgs e)
 {
     if (tvRYZ.SelectedNode == null)
     {
         Dlg.ShowErrorInfo("未选择要修改的角色!");
         return;
     }
     if (tvRYZ.SelectedNode.Text == "管理员")
     {
         Dlg.ShowErrorInfo("管理员角色不允许修改!");
         return;
     }
     using (FrmInput mForm = new FrmInput())
     {
         mForm.txtInput.Text = tvRYZ.SelectedNode.Text;
         int zbh = Convert.ToInt32(tvRYZ.SelectedNode.Tag);
         if (mForm.ShowDialog() == DialogResult.OK)
         {
             string sSql = string.Format("select count(*) from ptryz where zmc='{0}'", mForm.txtInput.Text.Trim());
             int    iRet = (int)SqlHelper.ExecuteScalar(sSql);
             if (iRet == -1)
             {
                 return;
             }
             if (iRet != 0)
             {
                 Dlg.ShowErrorInfoAndHelp(string.Format("输入的新角色名称“{0}”已存在,不能修改!", mForm.txtInput.Text.Trim()));
                 return;
             }
             sSql = string.Format("update ptryz set zmc='{0}' where zbh={1}", mForm.txtInput.Text.Trim(), zbh);
             int ret = SqlHelper.ExecuteNonQuery(sSql);
             InitRYZ();
         }
     }
 }
Example #5
0
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            if (tvRYZ.SelectedNode == null)
            {
                Dlg.ShowErrorInfoAndHelp("请选择用户的角色以分配权限!");
                return;
            }
            if (tvRYZ.SelectedNode.Text == "管理员")
            {
                Dlg.ShowErrorInfoAndHelp("管理员角色不允许修改权限!");
                return;
            }
            int           ryzbh = Convert.ToInt32(tvRYZ.SelectedNode.Tag);
            List <string> mSqls = new List <string>();

            mSqls.Add(string.Format("delete from ptzqx where ryzbh={0} and MKBH in (select MKBH from PTcd where MKBH <> '0000' and (cardtype in (-1,-2) or cardtype ={1}))", ryzbh, CommonClass.SttIC.iCardType));
            foreach (TreeNode tn in tvRight.Nodes)
            {
                AddSqlStr(ref mSqls, tn, ryzbh);
            }
            int ret = SqlHelper.ExecuteSqls(mSqls.ToArray());

            if (ret == 0)
            {
                Dlg.ShowOKInfo("保存成功");
                return;
            }
            else
            {
                Dlg.ShowErrorInfo("保存失败");
                return;
            }
        }
Example #6
0
        public static void Restore(string PFileName)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Title            = "数据库恢复";
            openFileDialog1.InitialDirectory = Application.StartupPath;
            openFileDialog1.Filter           = "备份文件(*.mdb)|*.mdb";
            openFileDialog1.ShowDialog();

            string strOldFile = openFileDialog1.FileName;

            if (strOldFile == PFileName)
            {
                Dlg.ShowErrorInfo("文件已存在!");
                return;
            }

            try
            {
                FileInfo fileInfo1 = new FileInfo(strOldFile);
                fileInfo1.CopyTo(PFileName, true);
                Dlg.ShowOKInfo("数据库恢复成功!");
                return;
            }
            catch
            {
                throw;
            }
        }
Example #7
0
        private void tsbResetPass_Click(object sender, EventArgs e)
        {
            //Confirm
            if (Dlg.ShowConfirmInfo("确认要重置密码吗?") == DialogResult.No)
            {
                return;
            }
            if (dgvRY.SelectedRows.Count < 1)
            {
                Dlg.ShowErrorInfoAndHelp("请先选择要重置的用户");
                return;
            }
            int gh = Convert.ToInt32(dgvRY.SelectedRows[0].Cells["ColGH"].Value);

            using (FrmInput mForm = new FrmInput())
            {
                if (mForm.ShowDialog() == DialogResult.OK)
                {
                    string strPass = mForm.txtInput.Text.Trim();
                    strPass = MD5.Md5Encrypt(strPass);

                    string mSql = string.Format("update ptry set mm='{0}' where gh='{1}'", strPass, gh);
                    int    ret  = SqlHelper.ExecuteNonQuery(mSql);
                    if (ret > 0)
                    {
                        Dlg.ShowOKInfo("重置成功!");
                    }
                    else
                    {
                        Dlg.ShowErrorInfo("重置失败!");
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// 执行SQL语句返回DataTable
        /// </summary>
        /// <param name="mSql">要执行Sql的语句</param>
        /// <returns></returns>
        public static DataTable GetData(string mSql, bool _blFlag = true)
        {
            DataTable mTable = new DataTable();

            try
            {
                using (OleDbConnection mConn = new OleDbConnection(CommonClass.ConnStr))
                {
                    mConn.Open();
                    using (OleDbDataAdapter adapter = new OleDbDataAdapter(mSql, mConn))
                    {
                        adapter.Fill(mTable);
                    }
                    mConn.Close();
                }
            }
            catch (Exception ex)
            {
                if (_blFlag)
                {
                    Dlg.ShowErrorInfo(ex.Message);
                }
                else
                {
                    throw ex;
                }
            }
            return(mTable);
        }
Example #9
0
        private object addControl(string senderName, string _sTitle = "")
        {
            try
            {
                Control mCT = null;

                if (PnlClient.Controls.Find(senderName, false).Length > 0) //该页面已存在
                {
                    mCT = PnlClient.Controls.Find(senderName, false)[0];
                }
                else
                {
                    Assembly myAs = Assembly.GetExecutingAssembly();

                    Type mType = myAs.GetType(senderName);
                    if (mType == null)
                    {
                        Dlg.ShowErrorInfoAndHelp("没有找到窗体");
                        return(1);
                    }
                    if (mType.BaseType.Name == "UserControl" || mType.BaseType.Name == "UserControlBase")
                    {
                        mCT      = (Control)Activator.CreateInstance(mType);
                        mCT.Name = senderName;
                    }

                    SetDoubleBuffered(mCT);
                    PnlClient.Controls.Add(mCT);
                    // mCT.Parent = panel1;
                    //将控件加载到标签页上
                }

                if (mCT != null)
                {
                    mCT.Dock = System.Windows.Forms.DockStyle.Fill;
                    mCT.BringToFront();
                    mCT.Select();
                }
                if (string.IsNullOrEmpty(_sTitle))
                {
                    LblTip.Text = senderName;
                }
                else
                {
                    LblTip.Text = _sTitle;
                }
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(string.Format("异常:\n{0}", ex.Message));
                return(1);
            }

            return(0);
            //0成功
        }
Example #10
0
 /// <summary>
 /// 执行所有Sql语句
 /// </summary>
 /// <param name="mSqls">要执行所有Sql语句</param>
 /// <returns></returns>
 public static int ExecuteSqls(string[] mSqls)
 {
     try
     {
         using (OleDbConnection mConn = new OleDbConnection(CommonClass.ConnStr))
         {
             mConn.Open();
             using (OleDbTransaction mTrans = mConn.BeginTransaction())
             {
                 try
                 {
                     using (OleDbCommand mComm = new OleDbCommand())
                     {
                         mComm.Connection  = mConn;
                         mComm.Transaction = mTrans;
                         int ret = 0;
                         foreach (string mSql in mSqls)
                         {
                             mComm.CommandText = mSql;
                             ret = mComm.ExecuteNonQuery();
                             if (ret < 1 && mSql.ToUpper().Contains("insert".ToUpper()) == true)
                             {
                                 mTrans.Rollback();
                                 return(1);
                             }
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     mTrans.Rollback();
                     Dlg.ShowErrorInfo(ex.Message);
                     return(1);
                 }
                 mTrans.Commit();
             }
             mConn.Close();
         }
     }
     catch (Exception ex)
     {
         Dlg.ShowErrorInfo(ex.Message);
         return(1);
     }
     return(0);
 }
Example #11
0
 public static void Timing(DateTime _DT)
 {
     try
     {
         SystemTime st = new SystemTime();
         st.wYear   = (ushort)_DT.Year;
         st.wMonth  = (ushort)_DT.Month;
         st.wDay    = (ushort)_DT.Day;
         st.Whour   = (ushort)_DT.Hour;
         st.wMinute = (ushort)_DT.Minute;
         st.wSecond = (ushort)_DT.Second;
         SetLocalTime(st);
     }
     catch (Exception Ex)
     {
         Dlg.ShowErrorInfo(string.Format("系统时间设置失败:\n{0}", Ex.Message));
     }
 }
        private void btnAudit2_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("确认审批不通过?", "提示", MessageBoxButtons.YesNo))
            {
                int    ret         = 0;
                string auditString = "";
                foreach (DataGridViewRow mRow in dgvNoTicketAudit.Rows)
                {
                    if (Convert.ToBoolean(mRow.Cells["ColumnChecked"].Value) == true)
                    {
                        auditString += mRow.Cells["idDataGridViewTextBoxColumn"].Value + ",";
                    }
                }
                auditString = auditString.TrimEnd(',');
                if (auditString == "")
                {
                    Dlg.ShowErrorInfoAndHelp("没有选择要审批的记录");
                    return;
                }

                string mSql = string.Format("UPDATE T_NoTicket SET Status = '{0}',AuditId = '{1}', AuditDate = GETDATE()  WHERE (Id IN ({2}))", "审批未通过", Classes.PubClass.UserId, auditString);

                ret = SqlHelper.ExecuteNonQuery(mSql);
                if (ret > 0)
                {
                    Dlg.ShowOKInfo("保存成功!");

                    //修改页面显示2016.9.6
                    refresh();

                    //foreach (DataGridViewRow mRow in dgvExAllocation.Rows)
                    //{
                    //    if (Convert.ToBoolean(mRow.Cells["ColumnChecked"].Value) == true)
                    //    {
                    //        dgvExAllocation.Rows.Remove(mRow);
                    //    }
                    //}
                }
                else
                {
                    Dlg.ShowErrorInfo("保存失败");
                }
            }
        }
Example #13
0
        int CheckLogin(string _sUserID, string _sPass)
        {
            string mSql;

            _sPass = MD5.Md5Encrypt(_sPass);
            mSql   = string.Format("SELECT mm,xm,jb,sh,zt FROM PTry WHERE gh='{0}' ", _sUserID);

            DataTable mTable = SqlHelper.GetData(mSql);

            if (mTable == null)
            {
                Dlg.ShowErrorInfo("获取操作员信息失败!");
                return(-1);
            }
            if (mTable.Rows.Count < 1)
            {
                Dlg.ShowErrorInfo("工号输入错误!");
                return(-1);
            }
            if (mTable.Rows[0]["zt"].ToString() == "1")
            {
                Dlg.ShowErrorInfo("该工号已被锁定,请联系管理员!");
                return(-1);
            }
            if (_sPass != mTable.Rows[0]["mm"].ToString())
            {
                Dlg.ShowErrorInfo("密码输入错误");
                return(-1);
            }
            CommonClass.OperatorID = _sUserID;
            try
            {
                CommonClass.OperatorType = Convert.ToInt32(mTable.Rows[0]["jb"]);
            }
            catch {}
            CommonClass.SttUser.sUserID   = _sUserID;
            CommonClass.SttUser.sUserName = mTable.Rows[0]["xm"].ToString();
            try
            {
                CommonClass.SttUser.iLevel = Convert.ToInt32(mTable.Rows[0]["jb"]);
            }
            catch { }
            return(0);
        }
Example #14
0
        public static void RefreshSection(string mConnStr)
        {
            try
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                config.ConnectionStrings.ConnectionStrings.Remove("PubClasses.Properties.Settings.Setting_ConnStr");
                config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("PubClasses.Properties.Settings.Setting_ConnStr", mConnStr, "System.Data.OleDb"));
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("ConnectionStrings");

                Dlg.ShowOKInfo("保存成功,程序将重新启动");
                Application.Restart();
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(ex.Message.ToString());
            }
        }
Example #15
0
        private int ChangeCardType(string xmlPath, string cardType)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                if (File.Exists(xmlPath) == false)
                {
                    xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "gb2312", null));
                    xmlDoc.AppendChild(xmlDoc.CreateElement("", "Config", ""));
                    xmlDoc.Save(xmlPath);
                }

                xmlDoc.Load(xmlPath);

                XmlNode mConfigNode = xmlDoc.SelectSingleNode("Config");
                if (mConfigNode == null)
                {
                    mConfigNode = xmlDoc.CreateElement("", "Config", "");
                    xmlDoc.AppendChild(mConfigNode);
                }
                XmlNode mCardTypeNode = xmlDoc.SelectSingleNode("Config/CardType");
                if (mCardTypeNode == null)
                {
                    mCardTypeNode = xmlDoc.CreateElement("CardType");
                    mConfigNode.AppendChild(mCardTypeNode);
                }
                XmlAttribute xaType = mCardTypeNode.Attributes["Type"];
                if (xaType == null)
                {
                    xaType = xmlDoc.CreateAttribute("Type");
                    mCardTypeNode.Attributes.Append(xaType);
                }
                xaType.Value = cardType;

                xmlDoc.Save(xmlPath);
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(ex.Message);
                return(1);
            }
            return(0);
        }
Example #16
0
        private void tsbRYDel_Click(object sender, EventArgs e)
        {
            if (dgvRY.SelectedRows.Count == 0)
            {
                return;
            }
            int gh = Convert.ToInt32(dgvRY.SelectedRows[0].Cells["ColGH"].Value);

            if (gh == 1001)
            {
                Dlg.ShowErrorInfoAndHelp("工号1001不能进行删除!");
                return;
            }
            //检查用户是否过做业务
            DbAccess DbAcs = new DbAccess(CommonClass.ConnStr);

            DbAcs.m_sSQL = string.Format("select count(*) from XTtradelist where operaterid='{0}'", gh);
            DataSet DS = DbAcs.GetDataSet();

            if (DS.ExtendedProperties["ReturnFlag"].ToString() != "0")
            {
                Dlg.ShowErrorInfo(DS.ExtendedProperties["ReturnFlag"].ToString());
                return;
            }
            if (DS.Tables[0].Rows[0][0].ToString() != "0")
            {
                Dlg.ShowErrorInfo("该用户已经做过业务,不能删除!");
                return;
            }
            //Confirm
            if (Dlg.ShowConfirmInfo("确认要删除该用户吗?") == DialogResult.No)
            {
                return;
            }
            string mSql = string.Format("delete from ptry where gh='{0}'", gh);
            int    ret  = SqlHelper.ExecuteNonQuery(mSql);

            if (ret > 0)
            {
                InitRY();
            }
        }
Example #17
0
 /// <summary>
 /// 测试是否能连接数据库
 /// </summary>
 /// <returns>0--成功,1--失败</returns>
 public static int TestDB()
 {
     try
     {
         //if (Common.mDatabaseClass.ConnectDB(PubClasses.Properties.Settings.Default.Setting_ConnStr) == false)
         if (ConnectDB(CommonClass.ConnStr) == false)
         {
             return(0);
         }
         else
         {
             return(1);
         }
     }
     catch (Exception ex)
     {
         Dlg.ShowErrorInfo(ex.Message);
         return(1);
     }
 }
Example #18
0
        private void btnTest1_Click(object sender, EventArgs e)
        {
            string ConnStr = null;

            ConnStr = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True;Jet OLEDB:Database Password=meiyoumima2011", txtAccess.Text);
            //;Persist Security Info=True;Jet OLEDB:Database Password=
            OleDbConnection mConn = new OleDbConnection(ConnStr);

            try
            {
                mConn.Open();
                mConn.Close();
                Dlg.ShowOKInfo("连接成功");
                BtnSaveAccess.Enabled = true;
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(ex.Message.ToString());
                BtnSaveAccess.Enabled = false;
            }
        }
Example #19
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string ConnStr = null;

            ConnStr = string.Format("provider=SQLOLEDB;Data Source={0},{1};Password={2};User ID={3};Initial Catalog={4}", txtAddress.Text, txtPort.Text, txtDBPass.Text, txtDBUser.Text, txtDBName.Text);
            //  //获取appSettings节点
            try
            {
                SqlHelper.RefreshSection(ConnStr);
                // My.Settings.ConnectionString = config.ConnectionStrings.ConnectionStrings("一卡通.Properties.Settings.Default.ConnectionString").ToString
                //MsgBox(My.Settings.ConnectionString)
                //Dlg.ShowOKInfo("保存成功,程序将重新启动");
                //Application.Restart();
                //Application.Exit()
                //Process.Start(Application.ExecutablePath.ToString)
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(ex.Message.ToString());
            }
        }
Example #20
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            string ConnStr = null;

            //Provider=SQLOLEDB;Data Source=.;Integrated Security=SSPI;Initial Catalog=DBMeter
            ConnStr = string.Format("Provider=SQLOLEDB;Data Source={0},{1};Password={2};User ID={3};Initial Catalog={4}", txtAddress.Text, txtPort.Text, txtDBPass.Text, txtDBUser.Text, txtDBName.Text);

            OleDbConnection mConn = new OleDbConnection(ConnStr);

            try
            {
                mConn.Open();
                mConn.Close();
                Dlg.ShowOKInfo("连接成功");
                BtnSave.Enabled = true;
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(ex.Message.ToString());
                BtnSave.Enabled = false;
            }
        }
Example #21
0
        /// <summary>
        /// 执行Sql语句返回受影响的行数
        /// </summary>
        /// <param name="mSql">要执行Sql的语句</param>
        /// <returns></returns>
        public static int ExecuteNonQuery(string mSql)
        {
            int ret = 0;

            try
            {
                using (OleDbConnection mConn = new OleDbConnection(CommonClass.ConnStr))
                {
                    mConn.Open();
                    using (OleDbCommand mComm = new OleDbCommand(mSql, mConn))
                    {
                        ret = mComm.ExecuteNonQuery();
                    }
                    mConn.Close();
                    return(ret);
                }
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(ex.Message);
                return(-1);
            }
        }
Example #22
0
        private void tsbDel_Click(object sender, EventArgs e)
        {
            if (tvRYZ.SelectedNode == null)
            {
                Dlg.ShowErrorInfo("未选择要删除的角色!");
                return;
            }
            if (tvRYZ.SelectedNode.Text == "管理员")
            {
                Dlg.ShowErrorInfo("管理员角色不允许删除!");
                return;
            }
            //Check
            DbAccess DbAcs = new DbAccess(CommonClass.ConnStr);

            DbAcs.m_sSQL = string.Format("SELECT count(*) FROM [PTry] where JB={0}", tvRYZ.SelectedNode.Tag.ToString());
            DataSet DS = DbAcs.GetDataSet();

            if (DS.ExtendedProperties["ReturnFlag"].ToString() != "0")
            {
                Dlg.ShowErrorInfo(DS.ExtendedProperties["ReturnFlag"].ToString());
                return;
            }
            if (DS.Tables[0].Rows[0][0].ToString() != "0")
            {
                Dlg.ShowErrorInfo("该系统角色已经做过分配,不能删除!");
                return;
            }
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////
            if (Dlg.ShowConfirmInfo("确认要删除该角色吗?") == DialogResult.Yes)
            {
                string mSql = string.Format("delete from ptryz where zbh={0}", Convert.ToInt32(tvRYZ.SelectedNode.Tag));
                int    ret  = SqlHelper.ExecuteNonQuery(mSql);
                InitRYZ();
                InitRight();
            }
        }
Example #23
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("Client");
            if (processes.Length > 1)
            {
                IntPtr hwnd = processes[0].MainWindowHandle;
                // NOTE: ensure the first intance handle selected
                if (System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle == hwnd)
                {
                    hwnd = processes[1].MainWindowHandle;
                }

                long style = GetWindowLong(hwnd, GWL_STYLE);

                if ((style & WS_MINIMIZE) == WS_MINIMIZE)
                {
                    ShowWindow(hwnd, SW_SHOWNOACTIVATE);
                }
                SetForegroundWindow(hwnd);
                return;
            }

            try
            {
                string dataDir = AppDomain.CurrentDomain.BaseDirectory;
                if (dataDir.EndsWith(@"\bin\Debug\") || dataDir.EndsWith(@"\bin\Release\"))
                {
                    dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
                    AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
                }

                string      xmlPath = "DBInfo.xml";
                XmlDocument xmlDoc  = new XmlDocument();
                if (File.Exists(xmlPath) == false)
                {
                    //文件不存在则新建文件
                    xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", null, null));

                    //根节点
                    xmlDoc.AppendChild(xmlDoc.CreateElement("DBInfo"));
                    xmlDoc.Save(xmlPath);

                    //应用程序所在目录下级目录用“/”,上级目录用“../”
                    Common.XmlHelper.Insert(xmlPath, "/DBInfo", "DBType", "", "0");
                    //XmlHelper.Insert(xmlPath, "/DBInfo", "DBConnStr", "", "Provider=SQLOLEDB;Data Source=192.168.111.115,1433;Persist Security Info=True;Password=sa;User ID=sa;Initial Catalog=DBMeter");
                    Common.XmlHelper.Insert(xmlPath, "/DBInfo", "DBConnStr", "", "");
                }

                string sConnStr = Common.XmlHelper.Read(xmlPath, "/DBInfo/DBConnStr", "");
                //解密数据库连接参数
                sConnStr = Soft.Common.Utils.DecryptRc2(sConnStr);
                //公共类的连接字符串赋值,包括类属性 和 项目属性两处
                //Common.Properties.Settings.Default.ConnectionString = Common.ConnStr;
                CommonClass.SetConnStr(sConnStr);

                if (SqlHelper.TestDB() == 0)
                {
                    //PubClasses.SqlHelper.mConnStr = mConnStr;
                }
                else
                {
                    Dlg.ShowErrorInfo("连接数据库失败,请运行“数据库连接参数配置工具.exe”进行配置!");
                    return;
                }
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(string.Format("异常:\n{0}", ex.Message));
                return;
            }

            Application.Run(new FrmLogin());
        }
Example #24
0
        private void OK_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;

            #region MyRegion
            //string LoginName, Password;

            //LoginName = txtLoginName.Text.Trim();
            //Password = txtPassword.Text.Trim();
            //var mTable = new T_UsersTableAdapter().GetDataByLoginName(LoginName);
            //if (mTable.Rows.Count < 1)
            //{
            //    Dlg.Show("登录名输入错误");
            //    return;
            //}
            //else
            //{
            //    var mRow = (SaleManager.DAL.DataSetUsers.T_UsersRow)mTable.Rows[0];
            //    Password =  PubClasses.MD5.Md5Encrypt(Password);
            //    if (string.Compare(Password, mRow.PassWord) != 0)
            //    {
            //        Dlg.Show("密码输入错误");
            //        txtPassword.Text = "";
            //        return;
            //    }
            //    PubClasses.Common.LoginName = LoginName;
            //    PubClasses.Common.UserId = mRow.id;
            //    PubClasses.Common.UserName = mRow.UserName;
            //    PubClasses.Common.UserRight = mRow.OperRight;
            //    PubClasses.Common.UserStatus = mRow.UserStatus;
            //    isLogined = true;
            //}
            //System.Net.IPAddress[] IPs = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
            //if (IPs.Length > 0)
            //{
            //    new T_LoginLogTableAdapter().Insert(PubClasses.Common.UserId, IPs[2].ToString());
            //}
            #endregion

            //object[] args = new object[2];
            //Assembly myAs;
            //myAs = Assembly.LoadFrom("一卡通.dll");

            //Type mType = myAs.GetType("一卡通.Classes.Login");

            //if (mType != null)
            //{

            //    args[0] = this;
            //    args[1] = "";
            //    int ret =-1;
            //    ret = (int)mType.InvokeMember("Login_Ok", BindingFlags.InvokeMethod, null, mType, args);

            //    if (ret != 0)
            //    {
            //        return;
            //    }
            //}
            //else
            //{

            //    Dlg.Show("加载登录模块失败!");
            //    return;
            //}
            //判断要加载的界面类型


            string UserId   = TBUserID.Text.Trim();
            string UserPass = TBUserPass.Text.Trim();
            CommonClass.SttUser.blSuperUser = false;
            if (UserId == "0000")
            {
                if (UserPass != "OneCardSuperAdmin")
                {
                    Dlg.ShowErrorInfo("密码不正确,重新输入!");
                    this.TBUserPass.SelectAll();
                    this.TBUserPass.Focus();
                    return;
                }
                CommonClass.SttUser.sUserID     = UserId;
                CommonClass.SttUser.sUserName   = "******";
                CommonClass.SttUser.blSuperUser = true;
            }
            else if (CheckLogin(UserId, UserPass) != 0)
            {
                return;
            }

            //Client.Common.OperatorName = mTable.Rows[0]["xm"].ToString();
            //Client.Common.NetNo = mTable.Rows[0]["sh"].ToString();

            ////04规范
            ////取 区域号,卡类型,只有一条
            ////DataSet ds1 = new DataSet();
            //mSql = "SELECT AreaNo,CardType FROM SZICSysParam";
            //mTable = Client.SqlHelper.GetData(mSql);

            //if (mTable.Rows.Count == 0)
            //{
            //    Dlg.ShowErrorInfo("请先进行系统参数(区域号,卡类型)设置!");
            //    return;
            //}
            //else
            //{
            //    Client.Common.gSysId = mTable.Rows[0]["AreaNo"].ToString().PadLeft(4, '0'); //区域号
            //    Client.Common.gCardType = mTable.Rows[0]["CardType"].ToString(); //卡类型
            //}

            ////取 读卡器端口号,条件是计算机名
            //string portStr = "USB";
            //string ComputerName = System.Environment.GetEnvironmentVariable("ComputerName");
            //mSql = string.Format("SELECT * FROM SZComputerParam where ComputerName='{0}'", ComputerName);
            //mTable = Client.SqlHelper.GetData(mSql);

            //if (mTable.Rows.Count == 0)
            //{
            //    Dlg.ShowErrorInfo("请先进行本机参数(读卡器端口号)设置!");
            //    //return;
            //}
            //else
            //{
            //    portStr = mTable.Rows[0]["Port"].ToString().Trim();
            //    object obj = mTable.Rows[0]["T57_flag"];
            //    if (obj != DBNull.Value)
            //    {
            //        Client.Common.gT57_flag = Convert.ToInt16(obj);
            //    }
            //}

            //if (portStr == "USB")
            //{
            //    Client.Common.gPortInt = 100;
            //}
            //else
            //{
            //    Client.Common.gPortInt = System.Convert.ToInt32(portStr.Substring(portStr.Length - 2, 2));
            //}
            ////04规范end

            ////取加密因子
            //mSql = "SELECT * FROM PTSoft_object";
            //mTable = PubClasses.SqlHelper.GetData(mSql);
            //if (mTable == null)
            //{
            //    Dlg.ShowErrorInfo("获取软件信息失败!");
            //    return;
            //}

            //if (mTable.Rows.Count == 0)
            //{
            //    Dlg.ShowErrorInfo("系统因子A不存在!");
            //    return;
            //}
            //else
            //{
            //    if (mTable.Rows[0]["JMA"] == DBNull.Value)
            //    {
            //        Dlg.ShowErrorInfo("系统因子A为空值!");
            //        return;
            //    }
            //    else
            //    {
            //        PubClasses.Common.JMA = mTable.Rows[0]["JMA"].ToString();
            //        if (PubClasses.Common.JMA.Length != 8)
            //        {
            //            Dlg.ShowErrorInfo("系统因子A长度错误!");
            //            return;
            //        }
            //    }

            //}
            FrmMain mForm = new FrmMain(this);
            mForm.LoadModuleListFromDb(CommonClass.OperatorType);
            //mForm.tssb用户名.Text = "登录用户名:" + Common.UserName + "  | 权限:" + PubClasses.Common.UserRight;
            mForm.Show();
            this.Hide();
        }
Example #25
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (blZhuxiao == false)
                {
                    if (Dlg.ShowConfirmInfo("确定退出系统?") == System.Windows.Forms.DialogResult.No)
                    {
                        e.Cancel = true;
                        return;
                    }
                    else
                    {
                        e.Cancel = false;
                        //return;

                        #region 取数据库备份参数
                        int    backupMode;
                        string backupPath;

                        string lsql = string.Format("SELECT IntCode,VcParam1 from SysParam where IntType=1");
                        using (DataTable dt = SqlHelper.GetData(lsql))
                        {
                            if (dt.Rows.Count == 0)
                            {
                                Dlg.ShowErrorInfoAndHelp("第一次使用,请设置数据库备份参数!");
                                e.Cancel = true;
                                return;
                            }
                            else
                            {
                                backupMode = Utils.StrToIntDef(dt.Rows[0]["IntCode"].ToString(), -1);
                                backupPath = Convert.ToString(dt.Rows[0]["VcParam1"]).Trim();
                            }

                            if ((backupMode < 0) || (backupMode > 2))
                            {
                                Dlg.ShowErrorInfo("数据库“备份选项”不正确,请设置!");
                                e.Cancel = true;
                                return;
                            }

                            if (backupMode != 2)
                            {
                                if (string.IsNullOrEmpty(backupPath) == true)
                                {
                                    if (Dlg.ShowConfirmInfo("数据库备份路径为空,请设置!") == System.Windows.Forms.DialogResult.Yes)
                                    {
                                        e.Cancel = true;
                                        return;
                                    }
                                }
                                if ((!Directory.Exists(backupPath)) && CommonClass.SttDb.iDBType == 0)
                                {
                                    if (Dlg.ShowConfirmInfo("数据库备份路径在本机不存在,请设置!") == System.Windows.Forms.DialogResult.Yes)
                                    {
                                        e.Cancel = true;
                                        return;
                                    }
                                }
                            }
                        }
                        #endregion

                        #region 备份
                        if (CommonClass.SttDb.iDBType == 0)
                        {
                            string dbFullName = Application.StartupPath + @"\DbMeter.mdb";
                            Cursor.Current = Cursors.WaitCursor;
                            CopyFileClass.Backup(backupMode, dbFullName, backupPath);
                            Cursor.Current = Cursors.Default;
                        }
                        else
                        {
                            if (backupMode == 0)
                            {
                                if (Dlg.ShowConfirmInfo("是否备份数据库") == System.Windows.Forms.DialogResult.Yes)
                                {
                                    Cursor.Current = Cursors.WaitCursor;
                                    string dbFullName = backupPath + "\\dbmeter" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak";
                                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\(.*?\)");
                                    string dbName = regex.Match(CommonClass.SttDb.sDbInfo).ToString().Trim('(', ')');
                                    string mSql   = string.Empty;
                                    mSql = string.Format(@"BACKUP DATABASE {0} TO  DISK = N'{1}' WITH  INIT ,  NOUNLOAD , NAME = N'{0}备份',NOSKIP , STATS = 10, NOFORMAT", dbName, dbFullName);
                                    SqlHelper.ExecuteNonQuery(mSql);
                                    Cursor.Current = Cursors.Default;
                                }
                            }
                            else if (backupMode == 1)
                            {
                                Cursor.Current = Cursors.WaitCursor;
                                string dbFullName = backupPath + "\\dbmeter" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak";
                                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\(.*?\)");
                                string dbName = regex.Match(CommonClass.SttDb.sDbInfo).ToString().Trim('(', ')');
                                string mSql   = string.Empty;
                                mSql = string.Format(@"BACKUP DATABASE {0} TO  DISK = N'{1}' WITH  INIT ,  NOUNLOAD , NAME = N'{0}备份',NOSKIP , STATS = 10, NOFORMAT", dbName, dbFullName);
                                SqlHelper.ExecuteNonQuery(mSql);
                                Cursor.Current = Cursors.Default;
                            }
                        }
                        #endregion

                        //关闭启动窗体
                        myLogin.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(ex.Message);
                e.Cancel = true;
                return;
            }
        }
Example #26
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtNewPass.Text.Trim() == string.Empty)
            {
                Dlg.ShowErrorInfo("新密码不能为空");
                return;
            }
            if (txtRePass.Text.Trim() == string.Empty)
            {
                Dlg.ShowErrorInfo("确认密码不能为空");
                return;
            }
            if (txtNewPass.Text.Trim().Equals(txtRePass.Text.Trim()) == false)
            {
                Dlg.ShowErrorInfo("新密码与确认密码不符");
                return;
            }

            try
            {
                //检查旧密码是否正确
                string _sPass = txtOldPass.Text.Trim();
                string mSql;
                //加密
                _sPass = MD5.Md5Encrypt(_sPass);
                mSql   = string.Format("SELECT mm FROM PTry WHERE gh='{0}' ", txtGH.Text.Trim());

                DataTable mTable = SqlHelper.GetData(mSql);
                if (mTable == null)
                {
                    Dlg.ShowErrorInfo("获取操作员信息失败!");
                    return;
                }
                if (mTable.Rows.Count < 1)
                {
                    Dlg.ShowErrorInfo("工号输入错误!");
                    return;
                }
                if (_sPass != mTable.Rows[0]["mm"].ToString())
                {
                    Dlg.ShowErrorInfo("原密码输入错误");
                    return;
                }

                //修改用户密码
                string _NewPass = txtNewPass.Text.Trim();
                _NewPass = MD5.Md5Encrypt(_NewPass);

                mSql = string.Format("update ptry set mm ='{0}' where gh='{1}'", _NewPass, txtGH.Text.Trim());

                int ret = SqlHelper.ExecuteNonQuery(mSql);

                if (ret > 0)
                {
                    Dlg.ShowOKInfo("修改成功!");
                    txtOldPass.Text = "";
                    txtNewPass.Text = "";
                    txtRePass.Text  = "";
                    return;
                }
                else
                {
                    Dlg.ShowOKInfo("修改失败!");
                    return;
                }
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(ex.Message);
                return;
            }
        }
Example #27
0
        private object addControl(string senderName, ModuleList mModule)
        {
            try
            {
                Control mCT = null;

                string sCtrlName = mModule.MKHSM;
                if (PnlClient.Controls.Find(sCtrlName, false).Length > 0) //该页面已存在
                {
                    mCT = PnlClient.Controls.Find(sCtrlName, false)[0];
                }
                else
                {
                    Assembly myAs;

                    string sDllFile = mModule.MKWJM;
                    if (File.Exists(sDllFile))
                    {
                        myAs = Assembly.LoadFrom(sDllFile);
                    }
                    else
                    {
                        myAs = Assembly.GetExecutingAssembly();
                    }
                    if (myAs == null)
                    {
                        Dlg.ShowErrorInfoAndHelp(string.Format("未找到程序集({0})", mModule.MKWJM));
                        return(null);
                    }

                    Type mType = myAs.GetType(sCtrlName);
                    if (mType == null)
                    {
                        Dlg.ShowErrorInfoAndHelp(string.Format("没有找到窗体({0})!", sCtrlName));
                        return(1);
                    }
                    mCT      = (Control)Activator.CreateInstance(mType);
                    mCT.Name = sCtrlName;
                    //if (mType.BaseType.Name != "Form" )
                    //{
                    //    mCT.BackColor = System.Drawing.Color.Transparent;
                    //}
                    SetDoubleBuffered(mCT);
                    //SetBackColorTransParent(mCT);
                    mCT.Dock = System.Windows.Forms.DockStyle.Fill;

                    if (mCT is Form)
                    {
                        mCT.Show();
                    }
                    else
                    {
                        mCT.Tag = mModule;
                        //PnlClient.Controls.Clear();
                        foreach (Control ctrl in PnlClient.Controls)
                        {
                            ctrl.Dispose();
                        }
                        PnlClient.Controls.Add(mCT);
                    }
                    // mCT.Parent = panel1;
                }

                if (mCT != null)
                {
                    //for (int i = 0; i < panel1.Controls.Count; i++)
                    //{
                    //    panel1.Controls[i].Dispose();
                    //}
                    mCT.BringToFront();
                    mCT.Select();
                }
                LblTip.Text = senderName;
            }
            catch (Exception ex)
            {
                Dlg.ShowErrorInfo(string.Format("异常:\n{0}", ex.Message));
                return(1);
            }
            return(0);  //0成功
        }