public ActionResult CustomerExcel(string sheetName, string fileName)
        {
            if (String.IsNullOrEmpty(sheetName))
            {
                sheetName = "工作表1";
            }
            if (String.IsNullOrEmpty(fileName))
            {
                fileName = string.Concat(DateTime.Now.ToString("yyyyMMddHHmmss"), ".xlsx");
            }

            var data           = CustomerRepo.All().Select(p => new { p.客戶名稱, p.統一編號, p.電話, p.傳真, p.地址, p.Email });
            var workbook       = new XLWorkbook();
            var MymemoryStream = new MemoryStream();
            //設置默認Style
            var style = workbook.Style;

            style.Font.FontName = "Microsoft YaHei";
            style.Font.FontSize = 16;
            var worksheet = workbook.Worksheets.Add(sheetName);

            worksheet.Cell(1, 1).Value = "客戶名稱";
            worksheet.Cell(1, 2).Value = "統一編號";
            worksheet.Cell(1, 3).Value = "電話";
            worksheet.Cell(1, 4).Value = "傳真";
            worksheet.Cell(1, 5).Value = "地址";
            worksheet.Cell(1, 6).Value = "Email";
            worksheet.Cell(2, 1).InsertData(data);

            workbook.SaveAs(MymemoryStream);

            return(File(MymemoryStream.ToArray(), "application/vnd.ms-excel", fileName));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "Id,客戶Id,銀行名稱,銀行代碼,分行代碼,帳戶名稱,帳戶號碼")] 客戶銀行資訊 客戶銀行資訊)
 {
     if (ModelState.IsValid)
     {
         var db = CustomerBankRepo.UnitOfWork.Context;
         db.Entry(客戶銀行資訊).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.客戶Id = new SelectList(CustomerRepo.All(), "Id", "客戶名稱", 客戶銀行資訊.客戶Id);
     return(View(客戶銀行資訊));
 }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,客戶Id,銀行名稱,銀行代碼,分行代碼,帳戶名稱,帳戶號碼")] 客戶銀行資訊 客戶銀行資訊)
        {
            if (ModelState.IsValid)
            {
                CustomerBankRepo.Add(客戶銀行資訊);
                CustomerBankRepo.UnitOfWork.Commit();
                return(RedirectToAction("Index"));
            }

            ViewBag.客戶Id = new SelectList(CustomerRepo.All(), "Id", "客戶名稱", 客戶銀行資訊.客戶Id);
            return(View(客戶銀行資訊));
        }
Exemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,客戶Id,職稱,姓名,Email,手機,電話")] 客戶聯絡人 客戶聯絡人)
 {
     if (ModelState.IsValid)
     {
         var db = CustomerContactRepo.UnitOfWork.Context;
         db.Entry(客戶聯絡人).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.客戶Id = new SelectList(CustomerRepo.All(), "Id", "客戶名稱", 客戶聯絡人.客戶Id);
     return(View(客戶聯絡人));
 }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "Id,客戶Id,職稱,姓名,Email,手機,電話")] 客戶聯絡人 客戶聯絡人)
        {
            if (ModelState.IsValid)
            {
                CustomerContactRepo.Add(客戶聯絡人);
                CustomerContactRepo.UnitOfWork.Commit();
                return(RedirectToAction("Index"));
            }

            ViewBag.客戶Id = new SelectList(CustomerRepo.All(), "Id", "客戶名稱", 客戶聯絡人.客戶Id);
            return(View(客戶聯絡人));
        }
        public ActionResult Index2(string IsExport)
        {
            //var data = db2.客戶資料
            //    .OrderByDescending(p => p.客戶名稱)
            //    .Select(p => new TestViewModel() {
            //        客戶名稱 = p.客戶名稱,
            //        聯絡人數量 = db2.客戶聯絡人.Count(d => d.客戶Id == p.Id) ,
            //        銀行帳戶數量 = db2.客戶銀行資訊.Count(b => b.客戶Id == p.Id)
            //    });

            var data = CustomerRepo.All()
                       .OrderByDescending(p => p.客戶名稱)
                       .Select(p => new TestViewModel()
            {
                客戶名稱   = p.客戶名稱,
                聯絡人數量  = p.客戶聯絡人.Count(d => d.客戶Id == p.Id),
                銀行帳戶數量 = p.客戶銀行資訊.Count(b => b.客戶Id == p.Id)
            });

            if (!string.IsNullOrEmpty(IsExport))
            {
                JArray jObjects = new JArray();

                foreach (var item in data)
                {
                    var jo = new JObject();
                    jo.Add("客戶名稱", item.客戶名稱);
                    jo.Add("聯絡人數量", item.聯絡人數量);
                    jo.Add("銀行帳戶數量", item.銀行帳戶數量);
                    jObjects.Add(jo);
                }

                var exportSpource = jObjects;
                var dt            = JsonConvert.DeserializeObject <DataTable>(exportSpource.ToString());

                var exportFileName = string.Concat(
                    "報表_",
                    DateTime.Now.ToString("yyyyMMddHHmmss"),
                    ".xlsx");

                return(new ExportExcelResult
                {
                    SheetName = "客戶資料",
                    FileName = exportFileName,
                    ExportData = dt
                });
            }
            return(View(data));
        }
Exemplo n.º 7
0
        // GET: CustomerContact/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            客戶聯絡人 客戶聯絡人 = CustomerContactRepo.Find(id.Value);

            if (客戶聯絡人 == null)
            {
                return(HttpNotFound());
            }
            ViewBag.客戶Id = new SelectList(CustomerRepo.All(), "Id", "客戶名稱", 客戶聯絡人.客戶Id);
            return(View(客戶聯絡人));
        }
Exemplo n.º 8
0
 // GET: CustomerBankInformation/Create
 public ActionResult Create()
 {
     ViewBag.客戶Id = new SelectList(CustomerRepo.All(), "Id", "客戶名稱");
     return(View());
 }