예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            bool isnew     = true;
            int  vistrisua = 0;

            if (!radioButton1.Checked)
            {
                if (cmb_nhomhs.SelectedValue == null || cmb_nhomhs.SelectedValue.ToString() == "-1")
                {
                    MessageBox.Show("Vui lòng chọn nhóm gian hàng", "Thông Báo");
                    return;
                }
            }

            dm_thitruongsi dm = new dm_thitruongsi();

            dm.id       = ConvertType.ToInt(txt_id.Text);
            dm.name     = txt_name.Text.Trim();
            dm.path     = txt_path.Text;
            dm.paren_id = radioButton1.Checked ? (int?)null : ConvertType.ToInt(cmb_nhomhs.SelectedValue);
            dm.orderid  = ConvertType.ToInt(txt_orderid.Text);
            if (dm.id == 0)
            {
                isnew = true;
                SQLDatabase.AdddmThiTruongSi(dm);
            }
            else
            {
                isnew     = false;
                vistrisua = dataGridView1.SelectedRows[0].Index;
                SQLDatabase.Updatedm_thitruongsi(dm);
            }

            if (radioButton1.Checked)
            {
                BindDM_NhomVatGia();
            }

            BindDMSanPham();

            if (isnew)
            {
                int nRowIndex = dataGridView1.Rows.Count - 1;
                if (dataGridView1.Rows.Count - 1 >= nRowIndex)
                {
                    dataGridView1.FirstDisplayedScrollingRowIndex   = nRowIndex;
                    dataGridView1.Rows[nRowIndex].Selected          = true;
                    dataGridView1.Rows[nRowIndex].Cells[0].Selected = true;
                }
            }
            else
            {
                dataGridView1.Rows[vistrisua].Selected = true;
            }
        }