示例#1
0
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Validate())
                {
                    return;
                }
                var train = new tblTrain();
                train.Number = txtNumberTrain.Text.Trim();
                var type = (short)((ComboBoxItem)ddlTypeName.SelectedItem).Value;
                train.Type = type;
                if (type == (short)TrainType.TypeExport || type == (short)TrainType.TypeExportChange || type == (short)TrainType.TypeExportNormal)
                {
                    train.IsExport   = true;
                    train.DateExport = CommonFactory.GetCurrentDate();
                }
                else
                {
                    train.IsImport   = true;
                    train.DateImport = CommonFactory.GetCurrentDate();
                }
                if (type == (short)TrainType.TypeExportChange || type == (short)TrainType.TypeImportChange)
                {
                    train.NumberHandover    = txtNumberHandover.Text.Trim();
                    train.DateHandover      = dtpHandover.Value;
                    train.CodeStation       = txtCodeCuaKhau.Text.Trim();
                    train.CodeStationFromTo = txtCodeGaDenDi.Text.Trim();
                    train.StatusVehicle     = txtStatusVehicle.Text.Trim();
                    train.StatusGoods       = txtStatusGood.Text.Trim();
                }

                train.CreatedBy = _userInfo.UserID;
                if (TrainFactory.Insert(train) > 0)
                {
                    //insert tờ khai
                    if (type == (short)TrainType.TypeExportNormal || type == (short)TrainType.TypeImportNormal)
                    {
                        var declare = new tblToKhaiTau()
                        {
                            Number          = Convert.ToInt32(txtExportNumber.Text.Trim()),
                            DateDeclaration = dtpDeclaration.Value,
                            TypeCode        = txtTypeExport.Text.Trim(),
                            CustomCode      = txtCustomsCode.Text.Trim(),
                            CreatedBy       = _userInfo.UserID,
                            //TrainID = train.TrainID
                        };
                        TrainFactory.InsertToKhai(declare);
                    }
                    //insert toa tàu
                    if (grdToaTau.Rows.Count > 0)
                    {
                        var listToaTau = new List <tblToaTau>();
                        for (int i = 0; i < grdToaTau.Rows.Count; i++)
                        {
                            var toaTau = (tblToaTau)grdToaTau.Rows[i].DataBoundItem;
                            toaTau.CreatedBy = _userInfo.UserID;
                            //toaTau.TrainID = train.TrainID;
                            listToaTau.Add(toaTau);
                        }
                        TrainFactory.InsertToaTau(listToaTau);
                    }

                    MessageBox.Show("Thêm mới thành công!");
                    Reset();
                }
                else
                {
                    MessageBox.Show("Thêm mới không thành công!");
                }
            }
            catch (Exception ex)
            {
                if (GlobalInfo.IsDebug)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }