Пример #1
0
        public HttpResponseMessage Get_PhuongTien()
        {
            string fileurl = "";
            var    package = GetTemplateWorkbook("DS-Xe.xlsx", "DS-Xe.xlsx", out fileurl);

            ExcelWorkbook workBook = package.Workbook;

            if (workBook != null)
            {
                var ws   = workBook.Worksheets.FirstOrDefault(); //Worksheets["DS"];
                var data = BS_CUS_VANTAI_CONF_PhuongTien.get_CUS_VANTAI_CONF_PhuongTien(db, PartnerID, QueryStrings);

                int rowid = 3;
                foreach (var item in data)
                {
                    ws.Cells["B" + rowid].Value = item.Sort; //STT
                    ws.Cells["C" + rowid].Value = item.Code;
                    ws.Cells["D" + rowid].Value = item.Name;


                    DTO_CUS_CRM_CONTRACT_NhomGiaPhuongTien nhomGia = BS_CUS_CRM_CONTRACT_NhomGiaPhuongTien.get_CUS_CRM_CONTRACT_NhomGiaPhuongTien(db, PartnerID, item.IDNhomGiaPhuongTien);
                    if (nhomGia != null)
                    {
                        ws.Cells["E" + rowid].Value = nhomGia.Code;
                    }

                    ws.Cells["F" + rowid].Value = item.ChuXe;
                    ws.Cells["G" + rowid].Value = item.TriGia;
                    ws.Cells["H" + rowid].Value = item.TiLe;

                    if (item.NgayMua.HasValue)
                    {
                        ws.Cells["I" + rowid].Value = item.NgayMua.Value.ToOADate();
                    }
                    if (item.NgayKiemDinh.HasValue)
                    {
                        ws.Cells["J" + rowid].Value = item.NgayKiemDinh.Value.ToOADate();
                    }
                    if (item.NgayHetHan.HasValue)
                    {
                        ws.Cells["K" + rowid].Value = item.NgayHetHan.Value.ToOADate();
                    }
                    ws.Cells["L" + rowid].Value = item.Remark;

                    rowid++;
                }

                package.Save();
            }

            return(downloadFile(fileurl));
        }
Пример #2
0
        public void AddListData(ExcelWorksheet ws)
        {
            var phuongTienList = BS_CUS_VANTAI_CONF_PhuongTien.get_CUS_VANTAI_CONF_PhuongTien(db, PartnerID, new Dictionary <string, string>());
            var nhanSuList     = BS_CUS_HRM_STAFF_NhanSu.get_CUS_HRM_STAFF_NhanSu(db, PartnerID, new Dictionary <string, string>());
            Dictionary <string, string> queryStrings = new Dictionary <string, string>();
            //queryStrings.Add("CodeTinhTrangLamViec", "\"PT1\", \"PT2\"");

            var lenhLamViecList = BS_CUS_VANTAI_WO_LenhLamViec.get_CUS_VANTAI_WO_LenhLamViec(db, PartnerID, queryStrings, true);
            //A.Xe
            //B.Tài xế
            //C.Phụ xe
            //D.Nội dung làm việc

            int rowid = 1;

            foreach (var item in phuongTienList)
            {
                rowid++;
                ws.Cells["A" + rowid].Value = item.Code + " [" + item.ID + "]";
            }

            rowid = 1;
            foreach (var item in nhanSuList)
            {
                if (item.IDChucDanh == 5 || item.IDChucDanh == 8 || item.IDChucDanh == 10 || item.IDChucDanh == 12)
                {
                    rowid++;
                    ws.Cells["B" + rowid].Value = item.TenDayDu + " [" + item.ID + "]";
                }
            }

            rowid = 1;
            foreach (var item in nhanSuList)
            {
                if (item.IDChucDanh == 6 || item.IDChucDanh == 9 || item.IDChucDanh == 11 || item.IDChucDanh == 14)
                {
                    rowid++;
                    ws.Cells["C" + rowid].Value = item.TenDayDu + " [" + item.ID + "]";
                }
            }


            rowid = 1;
            foreach (var item in lenhLamViecList)
            {
                rowid++;
                ws.Cells["D" + rowid].Value = item.Name + " [" + item.ID + "]";
            }
        }
Пример #3
0
        public HttpResponseMessage Post_PhuongTien()
        {
            string        fileurl  = "";
            var           package  = SaveImportedFile(out fileurl);
            ExcelWorkbook workBook = package.Workbook;

            if (workBook != null)
            {
                ExcelWorksheet ws        = workBook.Worksheets.FirstOrDefault();
                bool           haveError = false;


                int SheetColumnsCount, SheetRowCount = 0;

                SheetColumnsCount = ws.Dimension.End.Column;    // Find End Column
                SheetRowCount     = ws.Dimension.End.Row;       // Find End Row

                for (int rowid = 3; rowid <= SheetRowCount; rowid++)
                {
                    #region item
                    List <string> row = new List <string>();

                    for (int i = 2; i <= SheetColumnsCount; i++)
                    {
                        row.Add(ws.Cells[rowid, i].Value == null ? "" : ws.Cells[rowid, i].Value.ToString());
                    }

                    if (row[1] == "") //check code null
                    {
                        continue;
                    }

                    string code = row[1];
                    DTO_CUS_VANTAI_CONF_PhuongTien dbitem = BS_CUS_VANTAI_CONF_PhuongTien.get_CUS_VANTAI_CONF_PhuongTien(db, PartnerID, code);
                    if (dbitem == null)
                    {
                        dbitem = new DTO_CUS_VANTAI_CONF_PhuongTien();
                        dbitem.IDLoaiPhuongTien = 1;
                    }

                    if (int.TryParse(row[0], out int sort))
                    {
                        dbitem.Sort = sort;
                    }
                    dbitem.Code = row[1];
                    dbitem.Name = row[2];

                    if (!string.IsNullOrEmpty(row[3]))
                    {
                        DTO_CUS_CRM_CONTRACT_NhomGiaPhuongTien nhomGia = BS_CUS_CRM_CONTRACT_NhomGiaPhuongTien.get_CUS_CRM_CONTRACT_NhomGiaPhuongTien(db, PartnerID, row[3]);
                        if (nhomGia != null)
                        {
                            dbitem.IDNhomGiaPhuongTien = nhomGia.ID;
                        }
                        else
                        {
                            continue;
                        }
                    }


                    dbitem.ChuXe = row[4];


                    dbitem.TriGia = string.IsNullOrEmpty(row[5]) ? 0 : double.Parse(row[5]);

                    dbitem.TiLe = string.IsNullOrEmpty(row[6]) ? 1 : double.Parse(row[6]);

                    if (double.TryParse(row[7], out double d))
                    {
                        dbitem.NgayMua = DateTime.FromOADate(d);
                    }

                    if (double.TryParse(row[8], out double d2))
                    {
                        dbitem.NgayKiemDinh = DateTime.FromOADate(d2);
                    }

                    if (double.TryParse(row[9], out double d3))
                    {
                        dbitem.NgayHetHan = DateTime.FromOADate(d3);
                    }

                    dbitem.Remark = row[10];

                    try
                    {
                        if (dbitem.ID != 0)
                        {
                            BS_CUS_VANTAI_CONF_PhuongTien.put_CUS_VANTAI_CONF_PhuongTien(db, PartnerID, dbitem.ID, dbitem, Username);
                        }
                        else
                        {
                            BS_CUS_VANTAI_CONF_PhuongTien.post_CUS_VANTAI_CONF_PhuongTien(db, PartnerID, dbitem, Username);
                        }
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }



                    #endregion
                }


                if (haveError)
                {
                    package.Save();
                    return(downloadFile(fileurl, HttpStatusCode.Conflict));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            return(Request.CreateResponse(HttpStatusCode.Created));
        }
Пример #4
0
        public void AddRows(ExcelWorksheet ws)
        {
            var phuongTienList  = BS_CUS_VANTAI_CONF_PhuongTien.get_CUS_VANTAI_CONF_PhuongTien(db, PartnerID, new Dictionary <string, string>()).ToList();
            var lenhLamViecList = BS_CUS_VANTAI_WO_LenhLamViec.get_CUS_VANTAI_WO_LenhLamViec(db, PartnerID, new Dictionary <string, string>(), true);
            var nhanSuList      = BS_CUS_HRM_STAFF_NhanSu.get_CUS_HRM_STAFF_NhanSu(db, PartnerID, new Dictionary <string, string>());
            int rowid           = 1;

            foreach (var lenhLamViec in lenhLamViecList)
            {
                var nhatKyLamViecList = db.tbl_CUS_VANTAI_WO_NhatKyLamViec.Where(d => d.IsDeleted == false && d.IDPartner == PartnerID && d.IDLenhLamViec == lenhLamViec.ID).ToList();
                if (nhatKyLamViecList.Count() == 0 && lenhLamViec.NgayThucHien <= DateTime.Today && DateTime.Today <= lenhLamViec.NgayDuKienKetThuc && (lenhLamViec.IDTinhTrangLamViec == 2 || lenhLamViec.IDTinhTrangLamViec == 5))
                {
                    var tempNhatKy = new tbl_CUS_VANTAI_WO_NhatKyLamViec()
                    {
                        IDLenhLamViec = lenhLamViec.ID, IDPhuongTien = lenhLamViec.IDPhuongTien
                    };
                    tempNhatKy.NgayThucHien = DateTime.Today;
                    if (lenhLamViec.TaiXe.HasValue)
                    {
                        tempNhatKy.TaiXe = lenhLamViec.TaiXe.Value;
                    }
                    if (lenhLamViec.PhuXe.HasValue)
                    {
                        tempNhatKy.PhuXe = lenhLamViec.PhuXe.Value;
                    }

                    nhatKyLamViecList.Add(tempNhatKy);
                }

                foreach (var item in nhatKyLamViecList)
                {
                    rowid++;

                    //ws.Cells["A" + rowid].Value = item.ID;
                    ws.Cells["B" + rowid].Value = item.NgayThucHien.ToOADate();
                    var phuongtien = phuongTienList.FirstOrDefault(d => d.ID == item.IDPhuongTien);
                    if (phuongtien != null)
                    {
                        ws.Cells["C" + rowid].Value = phuongtien.Code + " [" + phuongtien.ID + "]";
                    }



                    ws.Cells["D" + rowid].Value = lenhLamViec.Name + " [" + lenhLamViec.ID + "]";

                    var taixe = BS_CUS_HRM_STAFF_NhanSu.get_CUS_HRM_STAFF_NhanSu(db, PartnerID, item.TaiXe);
                    if (taixe != null)
                    {
                        ws.Cells["E" + rowid].Value = taixe.TenDayDu + " [" + taixe.ID + "]";
                    }

                    var phuxe = BS_CUS_HRM_STAFF_NhanSu.get_CUS_HRM_STAFF_NhanSu(db, PartnerID, item.PhuXe.GetValueOrDefault());
                    if (phuxe != null)
                    {
                        ws.Cells["F" + rowid].Value = phuxe.TenDayDu + " [" + phuxe.ID + "]";
                    }

                    if (!string.IsNullOrEmpty(item.SangBatDau))
                    {
                        ws.Cells["G" + rowid].Value = TimeSpan.Parse(item.SangBatDau).TotalDays;
                    }
                    if (!string.IsNullOrEmpty(item.SangKetThuc))
                    {
                        ws.Cells["H" + rowid].Value = TimeSpan.Parse(item.SangKetThuc).TotalDays;
                    }
                    if (!string.IsNullOrEmpty(item.TruaBatDau))
                    {
                        ws.Cells["I" + rowid].Value = TimeSpan.Parse(item.TruaBatDau).TotalDays;
                    }
                    if (!string.IsNullOrEmpty(item.TruaKetThuc))
                    {
                        ws.Cells["J" + rowid].Value = TimeSpan.Parse(item.TruaKetThuc).TotalDays;
                    }
                    if (!string.IsNullOrEmpty(item.ChieuBatDau))
                    {
                        ws.Cells["K" + rowid].Value = TimeSpan.Parse(item.ChieuBatDau).TotalDays;
                    }
                    if (!string.IsNullOrEmpty(item.ChieuKetThuc))
                    {
                        ws.Cells["L" + rowid].Value = TimeSpan.Parse(item.ChieuKetThuc).TotalDays;
                    }
                    if (!string.IsNullOrEmpty(item.ToiBatDau))
                    {
                        ws.Cells["M" + rowid].Value = TimeSpan.Parse(item.ToiBatDau).TotalDays;
                    }
                    if (!string.IsNullOrEmpty(item.ToiKetThuc))
                    {
                        ws.Cells["N" + rowid].Value = TimeSpan.Parse(item.ToiKetThuc).TotalDays;
                    }

                    ws.Cells["O" + rowid].Formula = string.Format("N{0}-M{0}+L{0}-K{0}+J{0}-I{0}+H{0}-G{0}", rowid);
                    ws.Cells["P" + rowid].Value   = item.GiamSatThiCong;
                    ws.Cells["Q" + rowid].Value   = item.GiamSatThiCongXacNhan ? "ok" : "";
                    ws.Cells["R" + rowid].Value   = item.GiamSatThiCongNhanXet;
                    ws.Cells["S" + rowid].Value   = item.ChiHuyTruong;
                    ws.Cells["T" + rowid].Value   = item.ChiHuyTruongXacNhan ? "ok" : "";
                    ws.Cells["U" + rowid].Value   = item.ChiHuyTruongNhanXet;
                }
            }
        }