Ejemplo n.º 1
0
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            var dr = MessageBox.Show(ConstantInfo.CONFIRM_ADD_NEW, "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dr != DialogResult.Yes)
            {
                return;
            }

            try
            {
                if (!Validate())
                {
                    return;
                }
                //if (grdToaTau.RowCount == 0)
                //{
                //    MessageBox.Show("Bạn phải chọn ít nhất một toa tàu!");
                //    return;
                //}
                //kiem tra su trung lap so to khai
                if (TrainFactory.FindToKhaiTauByNumber(Int64.Parse(txtNumberToKhai.Text.Trim()), dtpDeclaration.Value, txtTypeCode.Text) != null)
                {
                    MessageBox.Show("Số tờ khai này đã tồn tại, xin nhập số khác!");
                    return;
                }
                var declaration = new tblToKhaiTau
                {
                    Type            = _type,
                    Number          = Int64.Parse(txtNumberToKhai.Text.Trim()),
                    DateDeclaration = dtpDeclaration.Value,
                    TypeCode        = txtTypeCode.Text.Trim(),
                    CustomCode      = txtCustomsCode.Text.Trim(),
                    CreatedBy       = _userInfo.UserID,
                    CreatedDate     = CommonFactory.GetCurrentDate()
                };
                foreach (var toaTau in _listToaTau)
                {
                    var declarationResource = new tblToKhaiTauResource
                    {
                        tblToaTau = toaTau
                    };
                    declaration.tblToKhaiTauResources.Add(declarationResource);
                }
                var result = TrainFactory.InsertToKhaiTau(declaration);
                if (result > 0)
                {
                    MessageBox.Show(string.Format("Thêm mới Tờ khai {0} thành công!", _type == 0 ? "xuất cảnh" : "nhập cảnh"));
                    Reset();
                }
                else
                {
                    MessageBox.Show("Thêm mới Tờ khai không thành công!");
                }
            }
            catch (Exception ex)
            {
                if (GlobalInfo.IsDebug)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }