Пример #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;
                }
                var train = TrainFactory.GetByCode(txtSoVanDon.Text.Trim());

                if (grdToaTau.RowCount == 0)
                {
                    MessageBox.Show("Bạn phải chọn ít nhất một toa tàu!");
                    return;
                }
                Nullable <DateTime> replyDate = null;
                if (cbReply.Checked)
                {
                    replyDate = dtpReplyDate.Value;
                }
                var handOver = new tblHandover
                {
                    NumberHandover    = txtNumberHandover.Text.Trim(),
                    DateHandover      = dtpHandover.Value,
                    CodeStation       = txtCodeCuaKhau.Text.Trim(),
                    CodeStationFromTo = txtCodeGaDenDi.Text.Trim(),
                    StatusGoods       = txtStatusGood.Text.Trim(),
                    StatusVehicle     = txtStatusVehicle.Text.Trim(),
                    CreatedBy         = _userInfo.UserID,
                    CreatedDate       = CommonFactory.GetCurrentDate(),
                    Type             = _type.ToString(),
                    IsReplied        = cbReply.Checked,
                    DateReply        = replyDate,
                    NoteReply        = cbReply.Checked?txtReplyNote.Text:null,
                    ReplyStatusGoods = cbReply.Checked ? txtReplyStatusGoods.Text : null,
                };
                foreach (var toaTau in listToaTau)
                {
                    var handOverResource = new tblHandoverResource
                    {
                        tblToaTau = toaTau
                    };
                    handOver.tblHandoverResources.Add(handOverResource);
                }

                var result = TrainFactory.InsertBBBG(handOver, _NumberGenerate);
                if (result > 0)
                {
                    if (cbPrint.Checked == true)
                    {
                        MessageBox.Show("Thêm mới Biên bản bàn giao thành công. Bạn hãy tắt hộp thoại này để xem bản in");
                        _handover = TrainFactory.FindHandoverByID(handOver.ID);
                        printBBBG();
                        Reset();
                    }
                    else
                    {
                        MessageBox.Show("Thêm mới Biên bản bàn giao thành công!");
                        Reset();
                    }
                }
                else
                {
                    MessageBox.Show("Thêm mới Biên bản bàn không thành công!");
                }
            }
            catch (Exception ex)
            {
                if (GlobalInfo.IsDebug)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }