Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            int  vistrisua = 0;
            bool isnew     = false;

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

            dm_batdongsan dm = new dm_batdongsan();

            dm.id   = ConvertType.ToInt(txt_id.Text);
            dm.name = txt_name.Text;
            dm.path = txt_path.Text;
            if (cmb_nhomhs.SelectedValue.ToString() != "-1")
            {
                dm.parenid = ConvertType.ToInt(cmb_nhomhs.SelectedValue);
            }

            dm.orderid = ConvertType.ToInt(txt_orderid.Text);

            if (dm.id == 0)
            {
                isnew = true;

                if (!radioButton1.Checked && ConvertType.ToInt(SQLDatabase.ExcScalar(string.Format("select count(*)  as soluong from dm_batdongsan  where path='{0}'", dm.path))) > 0)
                {
                    MessageBox.Show("Vui lòng chọn link khác, Link đã tồn tại", "Thông Báo");
                    txt_path.Focus();
                    txt_path.SelectAll();
                }
                else
                {
                    SQLDatabase.Adddm_batdongsang(dm);
                }
            }
            else
            {
                isnew     = false;
                vistrisua = dataGridView1.SelectedRows[0].Index;
                if (radioButton2.Checked)
                {
                    string str = string.Format("select count(*) as soluong from dm_batdongsan where id<>'{0}' and path='{1}'", dm.id, dm.path);
                    if (ConvertType.ToInt(SQLDatabase.ExcScalar(str)) > 0)
                    {
                        MessageBox.Show("Vui lòng chọn mã khác, Mã đã tồn tại", "Thông Báo");
                        txt_path.Focus();
                        txt_path.SelectAll();
                    }
                }
                else
                {
                    SQLDatabase.Updatedm_batdongsan(dm);
                }
            }

            BindDMNhom();
            BindDanhmuc();
            dataGridView1.ClearSelection();
            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;
            }
        }