Exemplo n.º 1
0
        private void btn_luu_Click(object sender, EventArgs e)
        {
            switch (option)
            {
            case Option.Nodata:

                break;

            case Option.Insert:
                var check_ten = Utils.err_null_data(txt_tennhaxuatban);
                if (check_ten != null)
                {
                    MessageBox.Show(check_ten);
                    break;
                }
                if (txt_sdt.Text != null && txt_sdt.Text != "")
                {
                    if (txt_sdt.Text.Length < 10 || txt_sdt.Text.Length > 11)
                    {
                        MessageBox.Show(Constants.error_sdt);
                        txt_sdt.Focus();
                        break;
                    }
                }
                get_info();
                //check if existing data
                var check = true;
                var data  = dtgv.Rows;
                foreach (DataGridViewRow item in data)
                {
                    if (int.Parse(item.Cells[0].Value.ToString()) == nhaxuatban_ett.manxb)
                    {
                        check = false;
                    }
                }
                if (!check)
                {
                    Utils.err_duplicate_data();
                    break;
                }
                var temp = nhaxuatban_ctrl.insert_nhaxuatban(nhaxuatban_ett);
                switch (temp.errcode)
                {
                case ErrorCode.NaN:
                    break;

                case ErrorCode.sucess:
                    MessageBox.Show(Constants.success_insert);
                    load_data();
                    Utils.erase_text_box(new List <TextBox> {
                        txt_manhaxuatban, txt_diachi, txt_sdt, txt_tennhaxuatban
                    });
                    break;

                case ErrorCode.fail:
                    break;

                default:
                    break;
                }
                break;

            case Option.Edit:
                if (txt_sdt.Text != null && txt_sdt.Text != "")
                {
                    if (txt_sdt.Text.Length < 10 || txt_sdt.Text.Length > 11)
                    {
                        MessageBox.Show(Constants.error_sdt);
                        txt_sdt.Focus();
                        break;
                    }
                }
                get_info();
                //check if existing data
                var check1 = true;
                var data1  = dtgv.Rows;
                foreach (DataGridViewRow item in data1)
                {
                    if (int.Parse(item.Cells[0].Value.ToString()) == nhaxuatban_ett.manxb)
                    {
                        check1 = false;
                    }
                }
                if (check1)
                {
                    Utils.err_no_duplicate_data();
                    break;
                }
                var temp1 = nhaxuatban_ctrl.edit_nhaxuatban(nhaxuatban_ett);
                switch (temp1.errcode)
                {
                case ErrorCode.NaN:
                    break;

                case ErrorCode.sucess:
                    MessageBox.Show(Constants.success_edit);
                    load_data();
                    Utils.erase_text_box(new List <TextBox> {
                        txt_manhaxuatban, txt_diachi, txt_sdt, txt_tennhaxuatban
                    });
                    Utils.readOnly_text_box(new List <TextBox> {
                        txt_diachi, txt_sdt, txt_tennhaxuatban
                    }, true);
                    break;

                case ErrorCode.fail:
                    if (Utils.switch_false())
                    {
                        MessageBox.Show(temp1.errInfor);
                    }
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }
        }