示例#1
0
        public static int InsertToKhaiTauResource(tblToKhaiTauResource resource)
        {
            var db = Instance();

            db.AddTotblToKhaiTauResources(resource);
            return(db.SaveChanges());
        }
示例#2
0
        public static int deleteToKhaiTauResource(tblToKhaiTauResource toKhaiTauResource)
        {
            var db = Instance();

            try
            {
                tblToKhaiTauResource originObj = db.tblToKhaiTauResources.Where(x => x.ID == toKhaiTauResource.ID).FirstOrDefault();
                if (originObj != null)
                {
                    db.DeleteObject(originObj);
                    return(db.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
            return(0);
        }
示例#3
0
        public static int UpdateToKhaiTau(tblToKhaiTau toKhaiTau, List <tblToaTau> listToaTau)
        {
            try
            {
                var db = Instance();

                //xoa cac toa tau cu thuoc to khai
                List <tblToKhaiTauResource> listReource = db.tblToKhaiTauResources.Where(x => x.tblToKhaiTau.ID == toKhaiTau.ID).ToList();
                foreach (tblToKhaiTauResource resource in listReource)
                {
                    deleteToKhaiTauResource(resource);
                }

                //cap nhat thong tin to khai tau
                tblToKhaiTau toKhaitauOrigin = db.tblToKhaiTaus.Where(x => x.ID == toKhaiTau.ID).FirstOrDefault();
                if (toKhaitauOrigin != null)
                {
                    toKhaitauOrigin.Number          = toKhaiTau.Number;
                    toKhaitauOrigin.DateDeclaration = toKhaiTau.DateDeclaration;
                    toKhaitauOrigin.TypeCode        = toKhaiTau.TypeCode;
                    toKhaitauOrigin.CustomCode      = toKhaiTau.CustomCode;
                    toKhaitauOrigin.ModifiedBy      = toKhaiTau.ModifiedBy;
                    toKhaitauOrigin.ModifiedDate    = CommonFactory.GetCurrentDate();

                    //them cac toa tau moi cho to khai
                    foreach (var toaTau in listToaTau)
                    {
                        var declarationResource = new tblToKhaiTauResource
                        {
                            tblToaTau = toaTau
                        };
                        toKhaitauOrigin.tblToKhaiTauResources.Add(declarationResource);
                    }

                    db.SaveChanges();
                }
                return(1);
            }
            catch (Exception)
            {
            }
            return(0);
        }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Int32 countTrain = 0, countToaTau = 0, countHandoder = 0, countDeclaration = 0, countEmpty = 0;

                int importExportTypeSearch = Convert.ToInt32(((ComboBoxItem)ddlImportExportType.SelectedItem).Value);

                List <tblChuyenTau> listTrain = TrainFactory.SearchChuyenTau("", Convert.ToInt32(((ComboBoxItem)ddlTypeName.SelectedItem).Value),
                                                                             true, dtpFrom.Value, dtpTo.Value);

                //if(importExportTypeSearch == 0) //chi list ke toa rong
                //{
                //   listTrain = listTrain.Where(x => x.tblToaTaus.Where( y => y.LoaiToaTau == (short)LoaiToaTau.ToaRong)).ToList();
                //}


                DataSet1  dataset = new DataSet1();
                DataTable dt      = dataset.ViewToaTau;

                foreach (tblChuyenTau train in listTrain)
                {
                    countTrain++;

                    if (train.tblToaTaus.IsLoaded == false)
                    {
                        train.tblToaTaus.Load();
                    }
                    List <tblToaTau> listToaTau = train.tblToaTaus.ToList();
                    foreach (tblToaTau toaTau in listToaTau)
                    {
                        countToaTau++;

                        string loaiToa      = "";
                        string loaiHinh     = "";
                        string soBBBG       = "";
                        string tenNguoiGui  = "";
                        string tenNguoiNhan = "";

                        if (importExportTypeSearch == 0) //chi list ke toa rong
                        {
                            if (toaTau.LoaiToaTau != (short)LoaiToaTau.ToaRong)
                            {
                                continue;
                            }
                        }

                        if (importExportTypeSearch == (int)ToaTauImportType.TaiCho) //chi list ke toa co loai hinh "tai cho"
                        {
                            if (toaTau.ImportExportType != (short)ToaTauImportType.TaiCho)
                            {
                                continue;
                            }
                        }

                        if (importExportTypeSearch == (int)ToaTauImportType.ChuyenCang) //chi list ke toa co loai hinh "chuyen cang"
                        {
                            if (toaTau.ImportExportType != (short)ToaTauImportType.ChuyenCang)
                            {
                                continue;
                            }
                        }

                        switch (toaTau.LoaiToaTau)
                        {
                        case (short)LoaiToaTau.ToaKin:
                            loaiToa = "Toa kín";
                            break;

                        case (short)LoaiToaTau.ToaRong:
                            loaiToa = "Toa rỗng";
                            countEmpty++;
                            break;

                        case (short)LoaiToaTau.ToaTran:
                            loaiToa = "Toa trần";
                            break;

                        default:
                            break;
                        }
                        switch (toaTau.ImportExportType)
                        {
                        case (short)ToaTauImportType.ChuyenCang:
                            loaiHinh = "Chuyển cảng";
                            try
                            {
                                if (toaTau.tblHandoverResources.IsLoaded == false)
                                {
                                    toaTau.tblHandoverResources.Load();
                                }
                                tblHandoverResource handoverResource = toaTau.tblHandoverResources.FirstOrDefault();
                                if (handoverResource != null)
                                {
                                    if (handoverResource.tblHandoverReference.IsLoaded == false)
                                    {
                                        handoverResource.tblHandoverReference.Load();
                                    }
                                    soBBBG = handoverResource.tblHandover.NumberHandover;
                                }
                            }
                            catch (Exception ex)
                            {
                                soBBBG = "";
                            }
                            countHandoder++;
                            break;

                        case (short)ToaTauImportType.TaiCho:
                            loaiHinh = "Tại chỗ";
                            try
                            {
                                if (toaTau.tblToKhaiTauResources.IsLoaded == false)
                                {
                                    toaTau.tblToKhaiTauResources.Load();
                                }
                                tblToKhaiTauResource toKhaiTauResources = toaTau.tblToKhaiTauResources.FirstOrDefault();
                                if (toKhaiTauResources != null)
                                {
                                    if (toKhaiTauResources.tblToKhaiTauReference.IsLoaded == false)
                                    {
                                        toKhaiTauResources.tblToKhaiTauReference.Load();
                                    }

                                    soBBBG = toKhaiTauResources.tblToKhaiTau.Number + "";
                                }
                            }
                            catch (Exception ex)
                            {
                                soBBBG = "";
                            }

                            countDeclaration++;
                            break;

                        default:
                            break;
                        }
                        if (train.Type == 0) //xuat
                        {
                            tenNguoiGui  = toaTau.Ten_DoanhNghiep;
                            tenNguoiNhan = toaTau.Ten_DoiTac;
                        }
                        else //nhap
                        {
                            tenNguoiGui  = toaTau.Ten_DoiTac;
                            tenNguoiNhan = toaTau.Ten_DoanhNghiep;
                        }


                        dt.Rows.Add(toaTau.ToaTauID, train.Ma_Chuyen_Tau, train.Ngay_XNC, toaTau.Ma_ToaTau, toaTau.So_VanTai_Don, tenNguoiGui, tenNguoiNhan, toaTau.Ten_Hang, toaTau.Don_Vi_Tinh, toaTau.Trong_Luong, soBBBG,
                                    toaTau.Seal_VanTai, toaTau.Seal_VanTai2, toaTau.Seal_HaiQuan, toaTau.Seal_HaiQuan2, loaiToa, loaiHinh, toaTau.Ghi_Chu);
                    }
                }


                var report  = new ReportTrainImportExport();
                var txtType = (TextObject)report.Section1.ReportObjects["txtType"];
                var txtFrom = (TextObject)report.Section1.ReportObjects["txtFrom"];
                var txtTo   = (TextObject)report.Section1.ReportObjects["txtTo"];

                var txtCountTrain       = (TextObject)report.Section1.ReportObjects["txtCountTrain"];
                var txtCountToaTau      = (TextObject)report.Section1.ReportObjects["txtCountToaTau"];
                var txtCountHandover    = (TextObject)report.Section1.ReportObjects["txtCountHandover"];
                var txtCountDeclaration = (TextObject)report.Section1.ReportObjects["txtCountDeclaration"];
                var txtCountEmpty       = (TextObject)report.Section1.ReportObjects["txtCountEmpty"];

                txtType.Text = ("SỔ THEO DÕI TÀU HÀNG " + ddlTypeName.Text).ToUpper();
                txtFrom.Text = txtFrom.Text + " " + dtpFrom.Text;
                txtTo.Text   = txtTo.Text + " " + dtpTo.Text;

                txtCountTrain.Text       = txtCountTrain.Text + " " + (countTrain != 0?countTrain.ToString("#.###"):"0");
                txtCountToaTau.Text      = txtCountToaTau.Text + " " + (countToaTau != 0?countToaTau.ToString("#.###"):"0");
                txtCountHandover.Text    = txtCountHandover.Text + " " + (countHandoder != 0? countHandoder.ToString("#.###"):"0");
                txtCountDeclaration.Text = txtCountDeclaration.Text + " " + (countDeclaration != 0?countDeclaration.ToString("#.###"):"0");
                txtCountEmpty.Text       = txtCountEmpty.Text + " " + (countEmpty != 0 ? countEmpty.ToString("#.###") : "0");

                report.SetDataSource(dataset);
                FrmPreviewReport frmReport = new FrmPreviewReport(report);
                frmReport.MdiParent = this.MdiParent;
                frmReport.Show();
            }

            catch (Exception ex)
            {
            }
        }
示例#5
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());
                }
            }
        }