예제 #1
0
        //string[] kinds = new string[] { "飯類","麵類","湯品","點心","飲料"};
        //int sale, cost;

        private void MealInformationForm_Load(object sender, EventArgs e)
        {
            LoginForm Lf3;

            Lf3 = new LoginForm();

            if (Lf3.id() != 0)
            {
                if (Lf3.id() != 1)
                {
                    btn_Insert.Enabled = false;
                    btn_Update.Enabled = false;
                    btn_Delete.Enabled = false;
                }
            }

            /*for(int i = 0; i < kinds.Length; i++)
             * {
             *  cboBox_Kind.Items.Add(kinds[i]);
             * }*/
            SqlConnection  cn = new SqlConnection(cnStr);
            SqlDataAdapter da = new SqlDataAdapter("SELECT sort , m_name , price FROM (SELECT c.sort , m.m_name , m.price FROM meals m JOIN categories c ON m.sort_id = c.sort_id) a", cn);
            DataSet        ds = new DataSet();

            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
            load();
        }
        private void EmployeeInformationForm_Load(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\TestDB.mdf;
            Integrated Security=True;Connect Timeout=30");

            cn.Open();

            //SqlCommand cmd = new SqlCommand("CREATE OR ALTER VIEW boss_view AS SELECT s.staff_id, j.job_title, s.s_name, s.salary, b.location_id , b.tel , s.password FROM staffs s JOIN jobs j ON(s.job_id = j.job_id) JOIN branches b ON(s.branch_id = b.branch_id) WHERE s.staff_id > 0", cn);
            //cmd.ExecuteNonQuery();
            //SqlDataAdapter da = new SqlDataAdapter(cmd);
            //DataSet ds = new DataSet();
            //da.Fill(ds);
            // DataTable dt = ds.Tables[0];

            //cmd = new SqlCommand(" CREATE OR ALTER VIEW menage_view AS SELECT s.staff_id, j.job_title, s.s_name, s.salary, b.location_id  FROM staffs s JOIN jobs j ON(s.job_id = j.job_id) JOIN branches b ON(s.branch_id = b.branch_id) WHERE s.staff_id > 20", cn);
            //cmd.ExecuteNonQuery();
            // da = new SqlDataAdapter(cmd);
            //ds = new DataSet();
            // da.Fill(ds);
            // dt = ds.Tables[1];

            //cmd = new SqlCommand("CREATE OR ALTER VIEW normal_view AS SELECT s.staff_id, j.job_title, s.s_name, s.salary ,b.location_id FROM staffs s JOIN jobs j ON(s.job_id = j.job_id) JOIN branches b ON(s.branch_id = b.branch_id)", cn);
            // cmd.ExecuteNonQuery();
            //da = new SqlDataAdapter(cmd);
            // ds = new DataSet();
            //da.Fill(ds);
            //dt = ds.Tables[2];
            //BOSS_VIEW MENAGE_VIEW NORMAL_VIEW 直接在資料庫中創建了!!(檢視表)

            load();
            load2();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet        ds = new DataSet();
            DataTable      dt = new DataTable();

            LoginForm Lf2;

            Lf2 = new LoginForm();

            if (Lf2.id() == 0)
            {
                da = new SqlDataAdapter("SELECT job_title ,s_name ,staff_id ,salary,location_id,tel,password  FROM boss_view ", cn);
                da.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];
                dt = ds.Tables[0];
            }
            else if (Lf2.id() == 1)
            {
                da = new SqlDataAdapter("SELECT job_title ,s_name ,staff_id ,salary,location_id  FROM menage_view ", cn);
                da.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];
                dt = ds.Tables[0];
            }
            else
            {
                da = new SqlDataAdapter("SELECT job_title ,s_name ,staff_id ,salary,location_id  FROM menage_view ", cn);
                da.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];
                dt = ds.Tables[0];
            }
            if (Lf2.id() != 0)
            {
                btn_Insert.Enabled = false;
                btn_Update.Enabled = false;
                btn_Delete.Enabled = false;
            }
            cn.Close();

            /*SqlConnection cn = new SqlConnection(cnStr);
             * SqlDataAdapter da = new SqlDataAdapter("SELECT job_title ,s_name ,staff_id,password ,salary,location_id,tel  FROM" +
             *   " (SELECT j.job_title , s.s_name ,s.staff_id , s.password , s.salary, b.location_id , b.tel FROM jobs j JOIN staffs s ON j.job_id = s.job_id JOIN branches b ON s.branch_id = b.branch_id) b", cn);
             * DataSet ds = new DataSet();
             * da.Fill(ds);
             * dataGridView1.DataSource = ds.Tables[0];*/
        }