コード例 #1
0
        private void S_Startup(object sender, StartupEventArgs e)
        {
            MainWindow mw = new MainWindow();

            if (System.Diagnostics.Process.GetProcessesByName("Imob - Sistema Imobiliario").Count() >= 2)       //Perguntar o Andre pq desse CONUT >= 2
            {
                EncerraApp();
            }
            else
            {
                ConectionString conString = new ConectionString();
                if (conString.ConectionStringExiste())
                {
                    mw.ShowDialog();
                }
                else
                {
                    CriarXmlConnectionString xml = new CriarXmlConnectionString();
                    xml.ShowDialog();

                    mw.ShowDialog();
                }
            }
        }
コード例 #2
0
        private void btnLogin_Click_1(object sender, EventArgs e)
        {
            // User u = new User();
            try
            {
                //SqlConnection con = new SqlConnection("Server=D8JZPCQ2;Database=dbPhoneShop;User ID=sa;Password=123");
                //con.Open();
                ConectionString con = new ConectionString();
                con.SetConnection();
                SqlCommand    cm       = new SqlCommand("select * from tbUser", con.con);
                SqlDataReader dr       = cm.ExecuteReader();
                string        username = txtUser.Text.Trim();
                string        password = txtPassword.Text.Trim();

                while (dr.Read())
                {
                    string user = dr["Username"].ToString();
                    string pass = dr["Password"].ToString();

                    if (username.Trim() == user && password.Trim() == pass)
                    {
                        string userId = dr["UserID"].ToString();
                        dr.Close();

                        sql = "select tbStaff.StaffPosition from tbUser inner join tbStaff on tbStaff.StaffID = tbUser.StaffID where tbUser.UserID=" + userId;
                        SqlCommand cmd = new SqlCommand("dbo.spRunSQL", con.con);
                        cmd.Parameters.AddWithValue("@sql", sql);
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlDataReader dtr = cmd.ExecuteReader();

                        while (dtr.Read())
                        {
                            string position = dtr[0].ToString();
                            if (position.ToLower() == "admin")
                            {
                                FrmMain m = new FrmMain();
                                this.Hide();
                                m.ShowDialog();
                                break;
                            }
                            if (position.ToLower() == "seller")
                            {
                                FrmSale s = new FrmSale();
                                this.Hide();
                                s.ShowDialog();
                                break;
                            }
                        }

                        //FrmSale u = new FrmSale();
                        //string userid = dr["UserID"].ToString();
                        //u.UserID = int.Parse(userId);
                        //u.ShowDialog();
                    }
                }
            }
            catch
            {
                // MessageBox.Show(ex.Message);
            }
        }