コード例 #1
0
        private void SalesManager_Load(object sender, EventArgs e)
        {
            //Create an object of type DataSet and name it as CollegeDS
            dsHiTechOrderManagement = new DataSet("HiTechDS");

            //Create an object of type DataTable and name it as Students
            // and add the object to the DataSet object
            dtCustomers = new DataTable("Customers");
            dsHiTechOrderManagement.Tables.Add(dtCustomers);
            //dsCollegeDB.Tables.Add("Students");

            // Create columns , add columns to the DataTable Students
            dtCustomers.Columns.Add("CustomerId", typeof(int));
            dtCustomers.Columns.Add("FirstName", typeof(string));
            dtCustomers.Columns.Add("LastName", typeof(string));
            dtCustomers.Columns.Add("Street", typeof(string));
            dtCustomers.Columns.Add("City", typeof(string));
            dtCustomers.Columns.Add("PostalCode", typeof(string));
            dtCustomers.Columns.Add("CreditLimit", typeof(int));
            dtCustomers.Columns.Add("PhoneNumber", typeof(int));
            dtCustomers.Columns.Add("FaxNumber", typeof(string));
            dtCustomers.PrimaryKey = new DataColumn[] { dtCustomers.Columns["CustomerId"] };
            da         = new SqlDataAdapter("SELECT * FROM Customers", UtilityDB.ConnectDB());
            SqlBuilder = new SqlCommandBuilder(da);
        }
コード例 #2
0
        //public static Employee SearchPasswordById(int empId)
        //{
        //    Employee emp = new Employee();
        //    string sqlSelect = "SELECT * FROM Employees " +
        //                       "WHERE employeeId = " + empId;

        //    SqlConnection sqlConn = UtilityDB.ConnectDB();
        //    SqlCommand sqlCmd = new SqlCommand(sqlSelect, sqlConn);
        //    SqlDataReader sqlReader = sqlCmd.ExecuteReader();

        //    if (sqlReader.Read())
        //    {
        //        emp.Password = sqlReader["Password"].ToString();
        //    }
        //    else
        //    {
        //        emp = null;
        //    }

        //    sqlConn.Close();
        //    return emp;
        //}

        public static bool ValidatePassword(int empId, string password)
        {
            bool success = false;

            try
            {
                Employee emp       = new Employee();
                string   sqlSelect = "SELECT * FROM Employees " +
                                     "WHERE employeeId = " + empId;

                SqlConnection sqlConn   = UtilityDB.ConnectDB();
                SqlCommand    sqlCmd    = new SqlCommand(sqlSelect, sqlConn);
                SqlDataReader sqlReader = sqlCmd.ExecuteReader();
                if (sqlReader.Read())
                {
                    emp.Password = sqlReader["Password"].ToString();
                }
                else
                {
                    emp = null;
                }

                if (emp.Password == password)
                {
                    success = true;
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }


            return(success);
        }
コード例 #3
0
 private void salesButtonList_Click(object sender, EventArgs e)
 {
     labelDSInfo.Visible = false;
     LabelDBinfo.Visible = true;
     da = new SqlDataAdapter("SELECT * FROM Clients", UtilityDB.ConnectDB());
     da.Fill(dsHiTech.Tables["Clients"]);
     dataGridViewSales.DataSource = dsHiTech.Tables["Clients"];
 }
コード例 #4
0
 private void ManagerForm_Load(object sender, EventArgs e)
 {
     dsHiTechDB  = new DataSet("HiTechDS");
     dtCustomers = new DataTable("Customers");
     dtCustomers.Columns.Add("CustomerId", typeof(Int32));
     dtCustomers.Columns.Add("CustomerName", typeof(string));
     dtCustomers.Columns.Add("Street", typeof(string));
     dtCustomers.Columns.Add("City", typeof(string));
     dtCustomers.Columns.Add("PostalCode", typeof(string));
     dtCustomers.Columns.Add("PhoneNumber", typeof(string));
     dtCustomers.Columns.Add("FaxNumber", typeof(string));
     dtCustomers.Columns.Add("CreditLimit", typeof(float));
     dtCustomers.PrimaryKey = new DataColumn[] { dtCustomers.Columns["CustomerId"] };
     dsHiTechDB.Tables.Add(dtCustomers);
     //MessageBox.Show(dsHiTechDB.Tables.Count.ToString());
     //MessageBox.Show(dsHiTechDB.Tables["Students"].ToString());
     da = new SqlDataAdapter("SELECT * FROM Customers", UtilityDB.ConnectDB());
     da.Fill(dsHiTechDB.Tables["Customers"]);
     //dataGridViewStudent.DataSource = dsHiTechDB.Tables["Students"];
 }
コード例 #5
0
        private void ButtonLogin_Click(object sender, EventArgs e)
        {
            if (userTextBox.Text == "")
            {
                HintUser.Text = " User Id cannot be empty";
            }
            else if (passTextBox.Text == "")
            {
                hint.Text = "Password cannot be empty";
            }
            else
            {
                SqlConnection connDB = UtilityDB.ConnectDB();
                SqlCommand    cmd    = new SqlCommand();
                cmd.Connection  = connDB;
                cmd.CommandText = "Select * from Login where UserId=@UserId and Password=@password";

                cmd.Parameters.AddWithValue("@UserId", userTextBox.Text);
                cmd.Parameters.AddWithValue("@password", passTextBox.Text);

                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataSet        ds    = new DataSet();
                adapt.Fill(ds);
                connDB.Close();
                int count = ds.Tables[0].Rows.Count;
                //If count is equal to 1, then show select form
                if (count == 1)
                {
                    SqlDataAdapter sda = new SqlDataAdapter("Select JobTitle from [User] where UserId='" + userTextBox.Text + "'", connDB);
                    DataTable      dt  = new DataTable();
                    sda.Fill(dt);
                    connDB.Close();
                    if (dt.Rows.Count == 1)
                    {
                        switch (dt.Rows[0]["JobTitle"].ToString())
                        {
                        case "MIS Manager":
                        {
                            this.Hide();
                            ManagementForm mm = new ManagementForm();
                            mm.Show();
                            break;
                        }

                        case "Sales Manager":
                        {
                            this.Hide();
                            CustomerForm um = new CustomerForm();
                            um.Show();
                            break;
                        }

                        default:
                        {
                            break;
                        }
                        }
                    }
                }

                else
                {
                    hint.Text = "Wrong Credentials";
                }
            }
        }
コード例 #6
0
        private void btnLogIn_Click(object sender, EventArgs e)
        {
            if (textBoxUserID.Text == "" || textBoxUserPassword.Text == "")
            {
                MessageBox.Show("Please enter UserID and Password");
                return;
            }

            try
            {
                SqlConnection connect = UtilityDB.ConnectDB();
                SqlCommand    cmd     = new SqlCommand();
                cmd.Connection  = connect;
                cmd.CommandText = "Select * from Users where userId = @userId and password = @password";
                cmd.Parameters.AddWithValue("@userId", textBoxUserID.Text);
                cmd.Parameters.AddWithValue("@password", textBoxUserPassword.Text);

                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataSet        ds    = new DataSet();
                adapt.Fill(ds);
                connect.Close();

                if (textBoxUserID.Text == "1111" && textBoxUserPassword.Text == "henry1234")
                {
                    MessageBox.Show("Login Successful!");
                    this.Hide();
                    ManagerForm mis = new ManagerForm();
                    mis.Show();
                }
                else if (textBoxUserID.Text == "1112" && textBoxUserPassword.Text == "thomas1234")
                {
                    MessageBox.Show("Login Successful!");
                    this.Hide();
                    SalesManager smf = new SalesManager();
                    smf.Show();
                }

                /*else if (textBoxUserID.Text == "4000" && textBoxUserPassword.Text == "kim4000")
                 * {
                 *  MessageBox.Show("Login Successful!");
                 *  this.Hide();
                 *  AccountantForm af = new AccountantForm();
                 *  af.Show();
                 * }*/
                else if (textBoxUserID.Text == "1113" && textBoxUserPassword.Text == "peter1234")
                {
                    MessageBox.Show("Login Successful!");
                    this.Hide();
                    InventoryForm mf = new InventoryForm();
                    mf.Show();
                }
                else if (textBoxUserID.Text == "1114" && textBoxUserPassword.Text == "mary1234")
                {
                    MessageBox.Show("Login Successful!");
                    this.Hide();
                    OrderForm of = new OrderForm();
                    of.Show();
                }
                else if (textBoxUserID.Text == "1115" && textBoxUserPassword.Text == "jennifer1234")
                {
                    MessageBox.Show("Login Successful!");
                    this.Hide();
                    OrderForm of = new OrderForm();
                    of.Show();
                }
                else
                {
                    MessageBox.Show("UserId or Password invalid!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #7
0
 private void button1_Click(object sender, EventArgs e)
 {
     MessageBox.Show(UtilityDB.ConnectDB().State.ToString(), "Database Connected");
 }
コード例 #8
0
        private void Change_Click(object sender, EventArgs e)
        {
            if (UsId.Text == "")
            {
                Hintuser.Text = "Please enter user id";
            }
            else if (ePassword.Text == "")
            {
                hintpassword.Text = "Please enter existing password";
                ;
            }
            else if (nPassword.Text == "")
            {
                hintnew.Text = "Please enter new password";
            }
            else if (confirm.Text == "")
            {
                hint.Text = "Please enter new password";
            }

            else if (nPassword.Text == confirm.Text)
            {
                try
                {
                    SqlConnection connDB = UtilityDB.ConnectDB();
                    SqlCommand    cmd    = new SqlCommand();
                    cmd.Connection  = connDB;
                    cmd.CommandText = "Select * from Login where LoginId=@UserId and Password=@password";
                    cmd.Parameters.AddWithValue("@UserId", UsId.Text);
                    cmd.Parameters.AddWithValue("@password", ePassword.Text);

                    SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                    DataSet        ds    = new DataSet();
                    adapt.Fill(ds);
                    connDB.Close();
                    int count = ds.Tables[0].Rows.Count;
                    //If count is equal to 1, than show select form
                    if (count == 1)
                    {
                        Login log = new Login();
                        log.UserId = Convert.ToInt32(UsId.Text.Trim());

                        log.Password = nPassword.Text.Trim();

                        log.UpdateLogin(log);

                        MessageBox.Show("Password updated successfully!", "Update Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Password Change Failed! Wrong Credentials");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                hint.Text = "New Password and Confirm Password should be same";
            }
        }
コード例 #9
0
        //button search
        protected void ButtonSearch_Click(object sender, EventArgs e)
        {
            if (TextBoxSearch.Text == "")
            {
                MessageBox.Show("Search input can't be empty!", "error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                switch (Convert.ToInt32(DropDownList1.SelectedIndex))
                {
                case 1:

                    Label1.Visible = false;
                    int           SearchId = Convert.ToInt32(TextBoxSearch.Text.Trim());
                    SqlConnection conn     = UtilityDB.ConnectDB();
                    SqlCommand    cmd      = new SqlCommand();
                    cmd.Connection  = conn;
                    cmd.CommandText = "Select * From Appartments where AppartmentId = @AppartmentId";
                    cmd.Parameters.AddWithValue("@AppartmentId", SearchId);

                    SqlDataReader reader = cmd.ExecuteReader();

                    listapp = app.SearchAppartments(reader);
                    if (listapp != null)
                    {
                        GridViewEmployee.DataSource = listapp;
                        GridViewEmployee.DataBind();
                        GridViewEmployee.Visible = true;
                    }
                    else
                    {
                        GridViewEmployee.DataSource = null;
                        GridViewEmployee.DataBind();
                        MessageBox.Show("Appartment not found !", "Message",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    break;

                case 2:

                    SearchId       = Convert.ToInt32(TextBoxSearch.Text.Trim());
                    conn           = UtilityDB.ConnectDB();
                    cmd            = new SqlCommand();
                    cmd.Connection = conn;

                    cmd.CommandText = "Select * From Appartments where NumberOfRoom = @NumberOfRoom";
                    cmd.Parameters.AddWithValue("@NumberOfRoom", SearchId);

                    reader = cmd.ExecuteReader();

                    listapp = app.SearchAppartments(reader);
                    if (listapp != null)
                    {
                        GridViewEmployee.DataSource = listapp;
                        GridViewEmployee.DataBind();
                        GridViewEmployee.Visible = true;
                    }
                    else
                    {
                        GridViewEmployee.DataSource = null;
                        GridViewEmployee.DataBind();
                        MessageBox.Show("Appartment not found !", "Message",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    break;

                case 3:

                    SearchId       = Convert.ToInt32(TextBoxSearch.Text.Trim());
                    conn           = UtilityDB.ConnectDB();
                    cmd            = new SqlCommand();
                    cmd.Connection = conn;

                    cmd.CommandText = "Select * From Appartments where NumberOfBath = @NumberOfBath";
                    cmd.Parameters.AddWithValue("@NumberOfBath", SearchId);

                    reader = cmd.ExecuteReader();

                    listapp = app.SearchAppartments(reader);
                    if (listapp != null)
                    {
                        GridViewEmployee.DataSource = listapp;
                        GridViewEmployee.DataBind();
                        GridViewEmployee.Visible = true;
                    }
                    else
                    {
                        GridViewEmployee.DataSource = null;
                        GridViewEmployee.DataBind();
                        MessageBox.Show("Appartment not found !", "Message",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    break;

                case 4:

                    SearchId       = Convert.ToInt32(TextBoxSearch.Text.Trim());
                    conn           = UtilityDB.ConnectDB();
                    cmd            = new SqlCommand();
                    cmd.Connection = conn;

                    cmd.CommandText = "Select * From Appartments where NumberOfParking = @NumberOfParking";
                    cmd.Parameters.AddWithValue("@NumberOfParking", SearchId);

                    reader = cmd.ExecuteReader();

                    listapp = app.SearchAppartments(reader);
                    if (listapp != null)
                    {
                        GridViewEmployee.DataSource = listapp;
                        GridViewEmployee.DataBind();
                        GridViewEmployee.Visible = true;
                    }
                    else
                    {
                        GridViewEmployee.DataSource = null;
                        GridViewEmployee.DataBind();
                        MessageBox.Show("Appartment not found !", "Message",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    break;

                case 5:

                    SearchId       = Convert.ToInt32(TextBoxSearch.Text.Trim());
                    conn           = UtilityDB.ConnectDB();
                    cmd            = new SqlCommand();
                    cmd.Connection = conn;

                    cmd.CommandText = "Select * From Appartments where FloorNum = @FloorNum";
                    cmd.Parameters.AddWithValue("@FloorNum", SearchId);

                    reader = cmd.ExecuteReader();

                    listapp = app.SearchAppartments(reader);
                    if (listapp != null)
                    {
                        GridViewEmployee.DataSource = listapp;
                        GridViewEmployee.DataBind();
                        GridViewEmployee.Visible = true;
                    }
                    else
                    {
                        GridViewEmployee.DataSource = null;
                        GridViewEmployee.DataBind();
                        MessageBox.Show("Appartment not found !", "Message",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    break;

                case 6:

                    Label1.Visible = true;
                    SearchId       = Convert.ToInt32(TextBoxSearch.Text.Trim());
                    conn           = UtilityDB.ConnectDB();
                    cmd            = new SqlCommand();
                    cmd.Connection = conn;

                    cmd.CommandText = "Select * From Appartments where PricePerMonth <= @PricePerMonth";
                    cmd.Parameters.AddWithValue("@PricePerMonth", SearchId);

                    reader = cmd.ExecuteReader();

                    listapp = app.SearchAppartments(reader);
                    if (listapp != null)
                    {
                        GridViewEmployee.DataSource = listapp;
                        GridViewEmployee.DataBind();
                        GridViewEmployee.Visible = true;
                    }
                    else
                    {
                        GridViewEmployee.DataSource = null;
                        GridViewEmployee.DataBind();
                        MessageBox.Show("Appartment not found !", "Message",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    break;
                }
            }
        }