Exemple #1
0
        private void btnPH_Click(object sender, EventArgs e)
        {
            PhongHu p = new PhongHu();

            p.ShowDialog();
        }
Exemple #2
0
        public Sua(PhongHu f)
        {
            FPhongHu = f;
            InitializeComponent();
            try
            {
                //string cnstr = "Server = .; Database = QLPH; Integrated Security = true;";
                //cn.ConnectionString = cnstr;

                if (cn != null && cn.State == ConnectionState.Closed)
                {
                    cn.Open();
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("Loi ket noi !!", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                cn.Close();
            }

            ////////////////////////////////////////////////////////////

            List <cbbItem> list = new List <cbbItem>();

            cn.Open();
            string        name;
            object        v;
            string        sql = "select MaPhong, TenPhong from Phong";
            SqlCommand    cmd = new SqlCommand(sql, cn);
            SqlDataReader dr  = cmd.ExecuteReader();

            while (dr.Read())
            {
                v    = Convert.ToString(dr.GetInt32(0));
                name = dr.GetString(1);
                cbbItem item = new cbbItem(name, v);
                list.Add(item);
            }
            dr.Close();
            cbbPhong.DataSource    = list;
            cbbPhong.DisplayMember = "Text";
            cbbPhong.ValueMember   = "Value";
            cbbPhong.Enabled       = true;


            ////////////////////////////////////////////////////////

            cbbItem cbb   = (cbbItem)cbbPhong.SelectedItem;
            string  value = cbb.Value.ToString();

            if (value != "")
            {
                if (cn != null && cn.State == ConnectionState.Closed)
                {
                    cn.Open();
                }
                string        sql1 = "select * from Phong where MaPhong like " + value;
                bool          mc, at, asang, ml, rdc;
                SqlCommand    cmd1 = new SqlCommand(sql1, cn);
                SqlDataReader dr1  = cmd1.ExecuteReader();
                while (dr1.Read())
                {
                    mc    = dr1.GetBoolean(2);
                    at    = dr1.GetBoolean(3);
                    asang = dr1.GetBoolean(4);
                    ml    = dr1.GetBoolean(5);
                    rdc   = dr1.GetBoolean(6);
                    if (mc == true)
                    {
                        radMCTot.Checked = true; radMCHong.Checked = false;
                    }
                    else
                    {
                        radMCTot.Checked = false; radMCHong.Checked = true;
                    }
                    if (at == true)
                    {
                        radATTot.Checked = true; radATHong.Checked = false;
                    }
                    else
                    {
                        radATTot.Checked = false; radATHong.Checked = true;
                    }
                    if (asang == true)
                    {
                        radASTot.Checked = true; radASHong.Checked = false;
                    }
                    else
                    {
                        radASTot.Checked = false; radASHong.Checked = true;
                    }
                    if (ml == true)
                    {
                        radMLTot.Checked = true; radMLHong.Checked = false;
                    }
                    else
                    {
                        radMLTot.Checked = false; radMLHong.Checked = true;
                    }
                    if (rdc == true)
                    {
                        radRDCTot.Checked = true; radRDCHong.Checked = false;
                    }
                    else
                    {
                        radRDCTot.Checked = false; radRDCHong.Checked = true;
                    }
                }
                dr1.Close();
            }
            cn.Close();
        }