Exemplo n.º 1
0
        public bool initialCon()
        {
            try
            {
                string strSql = "select wellNo,depName,gprsNo from tbWell";
                CDBConnection.getDataTable(ref CDBConnection.m_dtWellInfo, strSql, "tbWell");

                //报警下限
                strSql = String.Format("select val from tbInfo where des='报警下限'");
                string strWarnLevel = CDBConnection.ExecuteScalar(strSql);
                CDBConnection.m_iWarnLevel = Convert.ToInt32(strWarnLevel);

                //初始化售水表
                this.iniSalDt(ref CDBConnection.m_dtSal);
                //初始化指令集
                this.iniCmds(ref CDBConnection.m_htCmds);

                XmlDocument xDoc = new XmlDocument();
                xDoc.Load("Info.xml");

                string strServerType = xDoc.DocumentElement.SelectSingleNode("./tcpServer").Attributes.GetNamedItem("name").Value.ToString().Trim();
                if (strServerType == "server")
                {
                    CDBConnection.m_bServer = true;
                }
                else
                {
                    if (strServerType == "client")
                    {
                        CDBConnection.m_bClient = true;
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
Exemplo n.º 2
0
        public void EnableMenu(MainMenu mMenu)
        {
            try
            {
                SqlConnection sCon = new SqlConnection(BengZhan.CDBConnection.m_strCon);
                sCon.Open();
                string strUserID = CDBConnection.m_strUserID;

                string strSql           = String.Format("select parentManager from tbUsers where userID='{0}'", strUserID);
                string strParentManager = CDBConnection.ExecuteScalar(strSql);
                if (strParentManager.Trim() != "")
                {
                    strSql = String.Format("select userID from tbUsers where userName='******'", strParentManager.Trim());
                    string strUID = CDBConnection.ExecuteScalar(strSql).Trim();
                    strUserID = strUID;
                }

                strSql = String.Format("select menuName from userMenu where UserID='{0}'", strUserID);
                SqlCommand sCmd = new SqlCommand();
                sCmd.Connection  = sCon;
                sCmd.CommandText = strSql;
                DataSet        ds  = new DataSet();
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = sCmd;
                sda.Fill(ds, "userMenu");
                DataTable dtUserMenu = ds.Tables["userMenu"];

                for (int i = 0; i < mMenu.MenuItems.Count; i++)
                {
                    mMenu.MenuItems[i].Enabled = false;
                    mMenu.MenuItems[i].Visible = false;

                    string strParent = mMenu.MenuItems[i].Text.Trim();
                    for (int x = 0; x < dtUserMenu.Rows.Count; x++)
                    {
                        if (strParent == dtUserMenu.Rows[x][0].ToString().Trim())
                        {
                            mMenu.MenuItems[i].Enabled = true;
                            mMenu.MenuItems[i].Visible = true;
                            break;
                        }
                    }

                    for (int j = 0; j < mMenu.MenuItems[i].MenuItems.Count; j++)
                    {
                        mMenu.MenuItems[i].MenuItems[j].Visible = false;
                        mMenu.MenuItems[i].MenuItems[j].Enabled = false;

                        for (int y = 0; y < dtUserMenu.Rows.Count; y++)
                        {
                            string strChild = mMenu.MenuItems[i].MenuItems[j].Text.Trim();

                            if (strChild == dtUserMenu.Rows[y][0].ToString().Trim())
                            {
                                mMenu.MenuItems[i].MenuItems[j].Visible = true;
                                mMenu.MenuItems[i].MenuItems[j].Enabled = true;

                                break;
                            }
                        }
                    }
                }

//				for(int i=0;i<mMenu.MenuItems.Count;i++)
//				{
//					mMenu.MenuItems[i].Enabled=true;
//					mMenu.MenuItems[i].Visible=true;
//
//				}
                sCon.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (this.m_frm != null)
                {
                    this.m_frm.Close();
                }

                XmlDocument xDoc = new XmlDocument();
                xDoc.Load("Server.xml");
                string        strCon = xDoc.DocumentElement.SelectSingleNode("./strCon").InnerText.Trim();
                SqlConnection sCon   = new  SqlConnection(strCon);

                try
                {
                    sCon.Open();
                    BengZhan.CDBConnection.m_strCon = strCon;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("连接失败,请测试连接!");
                    return;
                }

                CDBConnection.m_sCon = sCon;

                string strSql = String.Format("select count(*) from tbUsers where userID='{0}' and userPwd='{1}'", this.txtUserName.Text.Trim(), this.txtPwd.Text.Trim());
                sCon = new SqlConnection(BengZhan.CDBConnection.m_strCon);
                sCon.Open();
                SqlCommand sCmd = new SqlCommand();
                sCmd.Connection  = sCon;
                sCmd.CommandText = strSql;
                string strCount = sCmd.ExecuteScalar().ToString();
                sCon.Close();
                int iCount = Convert.ToInt32(strCount);
                if (iCount <= 0)
                {
                    MessageBox.Show("用户ID或密码有误!");
                    return;
                }


                CDBConnection.m_strUserID = this.txtUserName.Text.Trim();

                strSql = String.Format("select userName from tbUsers where userID='{0}'", CDBConnection.m_strUserID);
                CDBConnection.m_strUserName = CDBConnection.ExecuteScalar(strSql);

                xDoc = new XmlDocument();
                xDoc.Load("Server.xml");

                xDoc.DocumentElement.SelectSingleNode("./load").Attributes.GetNamedItem("name").Value = CDBConnection.m_strUserID;
                xDoc.Save("Server.xml");

                if (BengZhan.tools.DBConnection.m_App != null)
                {
                    this.Close();
                    return;
                }
                BengZhan.tools.DBConnection.m_App = this;
                this.Hide();
                this.Visible = false;


                frmWaterSys frmWaterSysObj = new frmWaterSys();
                frmWaterSysObj.WindowState = System.Windows.Forms.FormWindowState.Maximized;

                frmWaterSysObj.Show();

                if (xDoc.DocumentElement.SelectSingleNode("./app") == null)
                {
                    return;
                }

                string strFile = xDoc.DocumentElement.SelectSingleNode("./app").Attributes.GetNamedItem("val").Value.Trim();

                System.Diagnostics.Process p = new System.Diagnostics.Process();

                p.StartInfo.WorkingDirectory = strFile;
                p.StartInfo.FileName         = "bengzhan.exe";
                //Info.WorkingDirectory
                p.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }