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

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

            dm_vatgia dm = new dm_vatgia();

            dm.id       = ConvertType.ToInt(txt_id.Text);
            dm.name     = txt_name.Text;
            dm.path     = txt_path.Text;
            dm.paren_id = radioButton1.Checked ? (int?)null : ConvertType.ToInt(comboBox1.SelectedValue);
            dm.orderid  = ConvertType.ToInt(txt_orderid.Text);
            if (dm.id == 0)
            {
                isnew = true;
                SQLDatabase.AdddmVatGia(dm);
            }
            else
            {
                isnew     = false;
                vistrisua = dataGridView1.SelectedRows[0].Index;
                SQLDatabase.UpdatedmVatGia(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;
            }
        }