Exemple #1
0
        public HttpResponseMessage Get_QuanHuyen()
        {
            string fileurl = "";
            var    package = GetTemplateWorkbook("DS-KhachHang.xlsx", "DS-KhachHang.xlsx", out fileurl);

            ExcelWorkbook workBook = package.Workbook;

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

                int rowid = 3;
                foreach (var item in data)
                {
                    ws.Cells["B" + rowid].Value = rowid - (rowid - 1); //STT
                    ws.Cells["C" + rowid].Value = item.Code;
                    ws.Cells["D" + rowid].Value = item.Name;
                    ws.Cells["E" + rowid].Value = item.MaSoThue;
                    ws.Cells["F" + rowid].Value = item.SoDienThoai1;
                    ws.Cells["G" + rowid].Value = item.SoDienThoai2;
                    ws.Cells["H" + rowid].Value = item.Fax;
                    ws.Cells["I" + rowid].Value = item.Email;
                    ws.Cells["J" + rowid].Value = item.Website;
                    ws.Cells["K" + rowid].Value = item.DiaChi;

                    rowid++;
                }

                package.Save();
            }

            return(downloadFile(fileurl));
        }
Exemple #2
0
        public HttpResponseMessage Get_KhachHang()
        {
            string fileurl = "";
            var    package = GetTemplateWorkbook("DS-KhachHang.xlsx", "DS-KhachHang.xlsx", out fileurl);

            ExcelWorkbook workBook = package.Workbook;

            if (workBook != null)
            {
                var ws   = workBook.Worksheets.FirstOrDefault(); //Worksheets["DS"];
                var data = BS_CUS_CRM_CONTACT_KhachHang.get_CUS_CRM_CONTACT_KhachHang(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;
                    ws.Cells["E" + rowid].Value = item.MaSoThue;
                    ws.Cells["F" + rowid].Value = item.SoDienThoai1;
                    ws.Cells["G" + rowid].Value = item.SoDienThoai2;
                    ws.Cells["H" + rowid].Value = item.Fax; //6
                    ws.Cells["I" + rowid].Value = item.Email;
                    ws.Cells["J" + rowid].Value = item.Website;
                    ws.Cells["K" + rowid].Value = item.DiaChi;
                    ws.Cells["L" + rowid].Value = item.IDQuanHuyen;//10
                    ws.Cells["M" + rowid].Value = item.IDTinhThanh;
                    ws.Cells["N" + rowid].Value = item.IDNhanSuChamSoc;
                    ws.Cells["O" + rowid].Value = item.Remark;//13
                    ws.Cells["P" + rowid].Value = item.IDLoaiKhachHang;
                    ws.Cells["Q" + rowid].Value = item.IDLinhVucKinhDoanh;
                    ws.Cells["R" + rowid].Value = item.IDQuyMoDoanhThu;
                    ws.Cells["S" + rowid].Value = item.IDQuyMoDoanhNghiep;
                    ws.Cells["T" + rowid].Value = item.SanPhamDichVu;
                    ws.Cells["U" + rowid].Value = item.BackgroundColor;//19

                    ws.Cells["V" + rowid].Value = item.IsDeleted;
                    ws.Cells["W" + rowid].Value = item.CreatedBy;
                    ws.Cells["X" + rowid].Value = item.CreatedDate;
                    ws.Cells["Y" + rowid].Value = item.ModifiedBy;
                    ws.Cells["Z" + rowid].Value = item.ModifiedDate;


                    rowid++;
                }

                package.Save();
            }

            return(downloadFile(fileurl));
        }
Exemple #3
0
        public HttpResponseMessage Post_QuanHuyen()
        {
            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].Text);
                    }

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

                    string code = row[1];
                    DTO_CUS_CRM_CONTACT_KhachHang dbitem = BS_CUS_CRM_CONTACT_KhachHang.get_CUS_CRM_CONTACT_KhachHang(db, PartnerID, code);
                    if (dbitem == null)
                    {
                        dbitem = new DTO_CUS_CRM_CONTACT_KhachHang();
                    }

                    dbitem.Code = row[1];
                    dbitem.Name = row[2];

                    dbitem.MaSoThue     = row[3];
                    dbitem.SoDienThoai1 = row[4];
                    dbitem.SoDienThoai2 = row[5];

                    dbitem.Fax     = row[6];
                    dbitem.Email   = row[7];
                    dbitem.Website = row[8];

                    dbitem.DiaChi = row[9];

                    try
                    {
                        if (dbitem.ID != 0)
                        {
                            BS_CUS_CRM_CONTACT_KhachHang.put_CUS_CRM_CONTACT_KhachHang(db, PartnerID, dbitem.ID, dbitem, Username);
                        }
                        else
                        {
                            BS_CUS_CRM_CONTACT_KhachHang.post_CUS_CRM_CONTACT_KhachHang(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));
        }