Пример #1
0
 public static void UpdateTKBDHistory(this TKBDHistory tkbd, TKBDHistoryViewModel vm)
 {
     tkbd.Id              = vm.Id;
     tkbd.Account         = vm.Account;
     tkbd.CustomerId      = vm.CustomerId;
     tkbd.CreatedBy       = vm.CreatedBy;
     tkbd.CreatedDate     = vm.CreatedDate;
     tkbd.Money           = vm.Money;
     tkbd.CustomerName    = vm.CustomerName;
     tkbd.Rate            = vm.Rate;
     tkbd.Status          = vm.Status;
     tkbd.TransactionDate = vm.TransactionDate;
     tkbd.UserId          = vm.UserId;
     tkbd.ServiceId       = vm.ServiceId;
 }
Пример #2
0
        private List <TKBDHistory> ReadTKBDFromExcel(string fullPath)
        {
            using (var package = new ExcelPackage(new FileInfo(fullPath)))
            {
                ExcelWorksheet       workSheet = package.Workbook.Worksheets.FirstOrDefault();
                List <TKBDHistory>   listTKBD  = new List <TKBDHistory>();
                TKBDHistoryViewModel tkbdViewModel;
                TKBDHistory          tkbdHistory;
                DateTime             transactionDate;
                DateTime             tranDate;
                decimal money;
                int     test = workSheet.Dimension.Start.Row + 1;
                int     end  = workSheet.Dimension.End.Row;
                for (int i = workSheet.Dimension.Start.Row + 1; i <= workSheet.Dimension.End.Row; i++)
                {
                    tkbdViewModel = new TKBDHistoryViewModel();
                    tkbdHistory   = new TKBDHistory();
                    //1
                    tkbdViewModel.CustomerName = workSheet.Cells[i, 2].Value.ToString();
                    //2
                    tkbdViewModel.CustomerId = workSheet.Cells[i, 3].Value.ToString();
                    //3
                    tkbdViewModel.Account = workSheet.Cells[i, 4].Value.ToString();
                    //4
                    tkbdViewModel.ServiceId = workSheet.Cells[i, 5].Value.ToString();
                    //5
                    if (DateTime.TryParseExact(workSheet.Cells[i, 6].Value.ToString(), "dd/MM/yyyy hh:mm:ss", null, DateTimeStyles.None, out transactionDate))
                    {
                        string temp = transactionDate.ToString("yyyy-MM-dd");
                        DateTime.TryParse(temp, out tranDate);
                        tkbdViewModel.TransactionDate = tranDate;
                    }
                    else
                    {
                        if (DateTime.TryParseExact(workSheet.Cells[i, 6].Value.ToString(), "MM/dd/yyyy hh:mm:ss", null, DateTimeStyles.None, out transactionDate))
                        {
                            string temp = transactionDate.ToString("yyyy-MM-dd");
                            DateTime.TryParse(temp, out tranDate);
                            tkbdViewModel.TransactionDate = tranDate;
                        }
                        else
                        {
                            transactionDate = DateTime.FromOADate(double.Parse(workSheet.Cells[i, 6].Value.ToString()));
                            if (transactionDate != null)
                            {
                                string temp = transactionDate.ToString("yyyy-MM-dd");
                                DateTime.TryParse(temp, out tranDate);
                                tkbdViewModel.TransactionDate = tranDate;
                            }
                            else
                            {
                                return(null);
                            }
                        }
                    }
                    //6
                    decimal.TryParse(workSheet.Cells[i, 8].Value.ToString().Replace(",", ""), out money);
                    tkbdViewModel.Money = money;
                    //7
                    if (_applicationUserService.getByUserName(workSheet.Cells[i, 9].Value.ToString()) != null)
                    {
                        tkbdViewModel.UserId = _applicationUserService.getByUserName(workSheet.Cells[i, 9].Value.ToString()).Id;
                    }
                    else
                    {
                        tkbdViewModel.UserId = "Người dùng không tồn tại";
                    }
                    //8 month
                    if (tkbdViewModel.TransactionDate != null)
                    {
                        tkbdViewModel.Month = tkbdViewModel.TransactionDate.Value.Month;
                        tkbdViewModel.Year  = tkbdViewModel.TransactionDate.Value.Year;
                        var code = tkbdViewModel.Year.ToString() + tkbdViewModel.Month.ToString();
                        tkbdViewModel.TimeCode = int.Parse(code);
                    }
                    tkbdViewModel.CreatedBy   = User.Identity.Name;
                    tkbdViewModel.CreatedDate = DateTime.Now;
                    tkbdViewModel.Status      = true;

                    tkbdHistory.UpdateTKBDHistory(tkbdViewModel);
                    listTKBD.Add(tkbdHistory);
                }
                return(listTKBD);
            }
        }