コード例 #1
0
        public Sheet this[string sheetName]
        {
            get
            {
                var sheet = _sheets.FirstOrDefault(f => f.Name == sheetName);

                if (sheet != null)
                {
                    return(sheet);
                }

                var openXmlSheet     = SpreadsheetHelper.GetSheet(OpenXmlDocument, sheetName, null, createIfDoesntExists: false);
                var openXmlSheetData = SpreadsheetHelper.GetSheetData(OpenXmlDocument, sheet: openXmlSheet);

                if (openXmlSheetData != null)
                {
                    sheet = new Sheet(this, openXmlSheet, openXmlSheetData);
                }
                else
                {
                    var maxInFile   = SpreadsheetHelper.GetMaxId(OpenXmlDocument);
                    var maxInMemory = _sheets.Any() ? _sheets.Max(m => m.Id) : 0;

                    var max = maxInFile > maxInMemory ? maxInFile : maxInMemory;

                    sheet = new Sheet(this, max + 1)
                    {
                        Name = sheetName
                    };
                }

                _sheets.Add(sheet);
                return(sheet);
            }
        }
コード例 #2
0
        public string DownloadQueryData(FetchSiteAnalyteQueryViewModel queryViewModel)
        {
            var selectedAnalytes = _variableRepository.GetAllChemistryVariables()
                                   .Where(x => queryViewModel.SelectedVariables.Contains(x.VariableID))
                                   .AsEnumerable();

            var matchedSite = _siteRepository.GetAll().Where(x => x.SamplingFeatureID == queryViewModel.SelectedSiteID).FirstOrDefault();
            var siteName    = (matchedSite == null || matchedSite.SamplingFeature == null || string.IsNullOrEmpty(matchedSite.SamplingFeature.SamplingFeatureName)) ?
                              "Unknown" :
                              matchedSite.SamplingFeature.SamplingFeatureName;

            var fileName = string.Format("{0}_Data_From_{1}_To_{2}.xlsx", siteName, queryViewModel.StartDate.ToString("MMM-dd-yyyy"), queryViewModel.EndDate.ToString("MMM-dd-yyyy"));

            var relativePathPart = Path.Combine("App_Data", "Query_Data", fileName);
            var fileFullPath     = HttpContext.Current.Server.MapPath("~/" + relativePathPart);

            var dataViewModel = FetchStationData(queryViewModel);
            var spreadSheet   = SpreadsheetHelper.GenerateQueryDataResultSpreadshet("Results", dataViewModel, selectedAnalytes);

            using (var fileStream = System.IO.File.Create(fileFullPath))
            {
                spreadSheet.Write(fileStream);
            }
            return(fileName);
        }
コード例 #3
0
        public ExcelValue this[BaseAZ column, int line]
        {
            get
            {
                var cell = SpreadsheetHelper.GetCell(Owner.OpenXmlSheetData, column, (uint)line, createIfDoesntExists: false);

                var value = SpreadsheetHelper.GetValue(Owner.Owner.OpenXmlDocument, Owner.OpenXmlSheetData, cell);

                return(new ExcelValue(value, cell?.DataType?.Value));
            }
            set
            {
                if (value == null || value.IsEmpty)
                {
                    var cell = SpreadsheetHelper.GetCell(Owner.OpenXmlSheetData, column, (uint)line, createIfDoesntExists: false);

                    cell?.Remove();
                }
                else
                {
                    Owner.Consolidate();

                    SpreadsheetHelper.SetValue(Owner.Owner.OpenXmlDocument, null, value.ToString(), value.ValueType, Owner.OpenXmlSheetData, column, (uint)line);
                }
            }
        }
コード例 #4
0
        public void ShouldInsertInSharedStringTable()
        {
            using (var rs = GetType().Assembly.GetManifestResourceStream("CcExcel.Test.Resources.AllTypes.xlsx"))
                using (var ms = new MemoryStream())
                {
                    rs.CopyTo(ms);

                    var doc = SpreadsheetDocument.Open(ms, true);

                    var newId = SpreadsheetHelper.InsertInSharedString(doc, "new value");

                    Assert.AreEqual(4, newId);

                    var sheetData = SpreadsheetHelper.GetSheetData(doc, "Sheet1");
                    var cell      = SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("B"), 12);

                    cell.CellValue = new Spreadsheet.CellValue("4");

                    doc.Save();

                    Assert.AreEqual("4", cell.InnerText);

                    DumpGeneratedExcelFiles.Dump(ms);
                }
        }
コード例 #5
0
        public void ShouldSetCellStyles()
        {
            using (var rs = GetType().Assembly.GetManifestResourceStream("CcExcel.Test.Resources.Styles.xlsx"))
                using (var ms = new MemoryStream())
                {
                    rs.CopyTo(ms);
                    ms.Position = 0;

                    using (var excel = new Excel(ms, ExcelMode.Open))
                    {
                        var style = excel["Sheet1"].Styles["B", 2];

                        for (var line = 3; line <= 6; line++)
                        {
                            excel["Sheet1"].Styles["B", line] = style;
                        }

                        excel.Save();
                    }

                    using (var excel = new Excel(ms, ExcelMode.OpenReadOnly))
                    {
                        var sheet = SpreadsheetHelper.GetSheetData(excel.OpenXmlDocument, "Sheet1");
                        var b     = BaseAZ.Parse("B");

                        Assert.AreEqual("3", SpreadsheetHelper.GetCell(sheet, b, 2).StyleIndex.InnerText);
                        Assert.AreEqual("3", SpreadsheetHelper.GetCell(sheet, b, 3).StyleIndex.InnerText);
                        Assert.AreEqual("3", SpreadsheetHelper.GetCell(sheet, b, 4).StyleIndex.InnerText);
                        Assert.AreEqual("3", SpreadsheetHelper.GetCell(sheet, b, 5).StyleIndex.InnerText);
                        Assert.AreEqual("3", SpreadsheetHelper.GetCell(sheet, b, 6).StyleIndex.InnerText);
                    }

                    DumpGeneratedExcelFiles.Dump(ms);
                }
        }
コード例 #6
0
        public void ShouldGetAllTypesOfValues()
        {
            using (var rs = GetType().Assembly.GetManifestResourceStream("CcExcel.Test.Resources.AllTypes.xlsx"))
                using (var doc = SpreadsheetDocument.Open(rs, false))
                {
                    var sd = SpreadsheetHelper.GetSheetData(doc, "Sheet1");
                    var b  = BaseAZ.Parse("B");

                    Assert.AreEqual("general", SpreadsheetHelper.GetValue(doc, sd, null, b, 2));
                    Assert.AreEqual("12.4568", SpreadsheetHelper.GetValue(doc, sd, null, b, 3));
                    Assert.AreEqual("45.25", SpreadsheetHelper.GetValue(doc, sd, null, b, 4));
                    Assert.AreEqual("18.56", SpreadsheetHelper.GetValue(doc, sd, null, b, 5));
                    Assert.AreEqual("32408", SpreadsheetHelper.GetValue(doc, sd, null, b, 6));
                    Assert.AreEqual("42952", SpreadsheetHelper.GetValue(doc, sd, null, b, 7));
                    Assert.AreEqual("0.49", SpreadsheetHelper.GetValue(doc, sd, null, b, 8));
                    Assert.AreEqual("0.1845", SpreadsheetHelper.GetValue(doc, sd, null, b, 9));
                    Assert.AreEqual("0.2", SpreadsheetHelper.GetValue(doc, sd, null, b, 10));
                    Assert.AreEqual("10500000", SpreadsheetHelper.GetValue(doc, sd, null, b, 11));
                    Assert.AreEqual("text1", SpreadsheetHelper.GetValue(doc, sd, null, b, 12));
                    Assert.AreEqual("text2", SpreadsheetHelper.GetValue(doc, sd, null, b, 13));
                    Assert.AreEqual("text1", SpreadsheetHelper.GetValue(doc, sd, null, b, 14));
                    Assert.AreEqual("text2", SpreadsheetHelper.GetValue(doc, sd, null, b, 15));
                    Assert.AreEqual("a", SpreadsheetHelper.GetValue(doc, sd, null, b, 16));
                    Assert.AreEqual("1", SpreadsheetHelper.GetValue(doc, sd, null, b, 17));
                    Assert.IsNull(SpreadsheetHelper.GetValue(doc, sd, null, b, 18));
                }
        }
コード例 #7
0
        public void Export(string filename, string email, int year, int month)
        {
            using (var helper = new SpreadsheetHelper(filename))
            {
                if (!helper.MoveWorksheet(sheetName))
                {
                    throw new ApplicationException("不正なテンプレートです。" + sheetName + "のシートがありません");
                }
                var worksheet = helper.CurrentSheet;
                helper.SetCellValue(emailAddressCell, email);
                using (var serverContext = ServerApplicationContext.CreateContext())
                {
                    var startDate = new DateTime(year, month, 1);
                    helper.SetCellValue(startDateCell, startDate);
                    var sb = new StringBuilder();

                    using (var workspace = serverContext.Application.CreateDataWorkspace())
                    {
                        foreach (WorkTime item in workspace.ApplicationData.WorkTimeSet.Where(x => x.UserId == email && x.WorkDate.Year == year && x.WorkDate.Month == month))
                        {
                            var rowIdx = item.WorkDate.Day - 1 + startPos;
                            helper.SetCellValue(4, rowIdx, item.SickHolidy);
                            helper.SetCellValue(9, rowIdx, item.StartTime);
                            helper.SetCellValue(11, rowIdx, item.EndTime);
                            helper.SetCellValue(16, rowIdx, item.Remark);
                        }
                    }
                }
                helper.Save(filename);
            }
        }
コード例 #8
0
ファイル: Sheet.cs プロジェクト: jonataspiazzi/CcExcel
        internal void Consolidate()
        {
            if (OpenXmlSheetData != null)
            {
                return;
            }

            OpenXmlSheet     = SpreadsheetHelper.GetSheet(Owner.OpenXmlDocument, Name, Id, createIfDoesntExists: true);
            OpenXmlSheetData = SpreadsheetHelper.GetSheetData(Owner.OpenXmlDocument, sheet: OpenXmlSheet);
        }
コード例 #9
0
        public void ShouldGetMaxId()
        {
            using (var rs = GetType().Assembly.GetManifestResourceStream("CcExcel.Test.Resources.MultiTabs.xlsx"))
                using (var doc = SpreadsheetDocument.Open(rs, false))
                {
                    var value = SpreadsheetHelper.GetMaxId(doc);

                    Assert.AreEqual(3, value);
                }
        }
コード例 #10
0
        public void ShouldGetSharedStringTable()
        {
            using (var rs = GetType().Assembly.GetManifestResourceStream("CcExcel.Test.Resources.AllTypes.xlsx"))
                using (var doc = SpreadsheetDocument.Open(rs, false))
                {
                    var sharedStringTable = SpreadsheetHelper.GetSharedString(doc);

                    Assert.IsNotNull(sharedStringTable);
                }
        }
 public ColumnToCollectionDataExtractor(
     Func <TRow, TCollection> getCollectionProperty,
     int headerRow,
     string startingColumn,
     ColumnToCollectionConfiguration <TCollectionItem> columnToCollectionConfiguration)
 {
     this.headerRow                       = headerRow;
     this.startingColumn                  = SpreadsheetHelper.ConvertColumnHeaderToNumber(startingColumn);
     this.getCollectionProperty           = getCollectionProperty;
     this.columnToCollectionConfiguration = columnToCollectionConfiguration;
 }
コード例 #12
0
        public void ShouldGetCell()
        {
            using (var rs = GetType().Assembly.GetManifestResourceStream("CcExcel.Test.Resources.AllTypes.xlsx"))
                using (var doc = SpreadsheetDocument.Open(rs, false))
                {
                    var sheetData = SpreadsheetHelper.GetSheetData(doc, "Sheet1");
                    var cell      = SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("B"), 2);

                    Assert.IsNotNull(cell);
                }
        }
コード例 #13
0
        public void ShouldGetSheetDataInSteps()
        {
            using (var rs = GetType().Assembly.GetManifestResourceStream("CcExcel.Test.Resources.AllTypes.xlsx"))
                using (var doc = SpreadsheetDocument.Open(rs, false))
                {
                    var sheet = SpreadsheetHelper.GetSheet(doc, "Sheet1");

                    var sheetData = SpreadsheetHelper.GetSheetData(doc, sheet: sheet);

                    Assert.IsNotNull(sheetData);
                }
        }
コード例 #14
0
 public NewableColumnToCollectionDataExtractor(
     Expression <Func <TRow, TCollection> > collectionPropertyExpr,
     int headerRow,
     string startingColumn,
     ColumnToCollectionConfiguration <TCollectionItem> columnToCollectionConfiguration)
 {
     this.headerRow                       = headerRow;
     this.startingColumn                  = SpreadsheetHelper.ConvertColumnHeaderToNumber(startingColumn);
     this.setCollectionProperty           = collectionPropertyExpr.CreatePropertyValueSetterAction();
     this.getCollection                   = collectionPropertyExpr.Compile();
     this.columnToCollectionConfiguration = columnToCollectionConfiguration;
 }
コード例 #15
0
        private SpreadsheetDocument LoadDocument(ExcelMode mode)
        {
            var doc = mode == ExcelMode.Create
                ? SpreadsheetDocument.Create(_stream, SpreadsheetDocumentType.Workbook, true)
                : SpreadsheetDocument.Open(_stream, IsEditable);

            if (mode == ExcelMode.Create)
            {
                SpreadsheetHelper.GetWorkbook(doc, createIfDoesntExists: true);
            }

            return(doc);
        }
コード例 #16
0
        public void ShouldCreateSheetCells()
        {
            using (var ms = new MemoryStream())
            {
                using (var doc = SpreadsheetDocument.Create(ms, SpreadsheetDocumentType.Workbook, true))
                {
                    var sheetData = SpreadsheetHelper.GetSheetData(doc, "Sheet3", createIfDoesntExists: true);

                    Action <string, uint, int> setCell = (column, line, value) =>
                    {
                        var azColumn = BaseAZ.Parse(column);
                        var valueStr = value.ToString();

                        SpreadsheetHelper.GetCell(sheetData, azColumn, line, createIfDoesntExists: true).CellValue
                            = new DocumentFormat.OpenXml.Spreadsheet.CellValue(valueStr);
                    };

                    setCell("C", 3, 5);
                    setCell("C", 1, 8);
                    setCell("C", 5, 2);
                    setCell("A", 3, 4);
                    setCell("A", 1, 7);
                    setCell("A", 5, 1);
                    setCell("E", 3, 6);
                    setCell("E", 1, 9);
                    setCell("E", 5, 3);

                    doc.Save();
                    doc.Dispose();
                }

                using (var doc = SpreadsheetDocument.Open(ms, true))
                {
                    var sheetData = SpreadsheetHelper.GetSheetData(doc, "Sheet3");

                    Assert.AreEqual("1", SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("A"), 5).CellValue.InnerText);
                    Assert.AreEqual("2", SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("C"), 5).CellValue.InnerText);
                    Assert.AreEqual("3", SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("E"), 5).CellValue.InnerText);
                    Assert.AreEqual("4", SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("A"), 3).CellValue.InnerText);
                    Assert.AreEqual("5", SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("C"), 3).CellValue.InnerText);
                    Assert.AreEqual("6", SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("E"), 3).CellValue.InnerText);
                    Assert.AreEqual("7", SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("A"), 1).CellValue.InnerText);
                    Assert.AreEqual("8", SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("C"), 1).CellValue.InnerText);
                    Assert.AreEqual("9", SpreadsheetHelper.GetCell(sheetData, BaseAZ.Parse("E"), 1).CellValue.InnerText);

                    doc.Dispose();
                }

                DumpGeneratedExcelFiles.Dump(ms);
            }
        }
コード例 #17
0
        /*private ObservableCollection<MemberInfo> GetMember()
         * {
         *  return new ObservableCollection<MemberInfo>()
         *  {
         *      new MemberInfo()
         *      {
         *          UserName="******",
         *          Alias="aaa",
         *          WsAlias="ddd",
         *          Technology="ooo",
         *          Group="ssss",
         *          VacationHour=6,
         *      },
         *  };
         * }*/

        async public void Readfile()
        {
            Stream finalstream = await SpreadsheetHelper.filepathhelper();

            try
            {
                members      = SpreadsheetHelper.ReadDataFromExcel(finalstream, "Sheet1", "A2", "F29");
                this.Members = members;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message.ToString());
            }
        }
コード例 #18
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Stream finalstream = await SpreadsheetHelper.filepathhelper();

                SpreadsheetHelper.ReadDataFromExcel(finalstream, "Sheet1", "A2", "F35", memcoll);
                mycollection = memcoll;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message.ToString());
            }
        }
コード例 #19
0
        public Sheet this[int sheetId]
        {
            get
            {
                var sheet = _sheets.FirstOrDefault(f => f.Id == sheetId);

                var openXmlSheet     = SpreadsheetHelper.GetSheet(OpenXmlDocument, null, sheetId, createIfDoesntExists: false);
                var openXmlSheetData = SpreadsheetHelper.GetSheetData(OpenXmlDocument, sheet: openXmlSheet);

                sheet = openXmlSheetData != null
                    ? new Sheet(this, openXmlSheet, openXmlSheetData)
                    : new Sheet(this, sheetId);

                _sheets.Add(sheet);
                return(sheet);
            }
        }
コード例 #20
0
 public IActionResult GetPassengerOrdersSpreadsheet([FromQuery] string passengerId, [FromQuery] string formatType)
 {
     try
     {
         if (formatType == "xls")
         {
             var    orders     = getPassengerOrders(passengerId);
             var    workbook   = SpreadsheetHelper.GenerateSpreadSheet(orders);
             string fileName   = "orders_" + Guid.NewGuid().ToString() + ".xlsx";
             var    fileStream = new MemoryStream();
             workbook.Write(fileStream);
             fileStream.Position = 0;
             return(File(fileStream, "application/octet-stream", fileName));
         }
         return(BadRequest());
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
コード例 #21
0
        public uint?this[BaseAZ column, int line]
        {
            get
            {
                var cell = SpreadsheetHelper.GetCell(Owner.OpenXmlSheetData, column, (uint)line, createIfDoesntExists: false);

                return(cell.StyleIndex);
            }
            set
            {
                Owner.Consolidate();

                var cell = SpreadsheetHelper.GetCell(Owner.OpenXmlSheetData, column, (uint)line, createIfDoesntExists: true);

                if (cell.CellValue == null)
                {
                    cell.CellValue = new CellValue(null);
                }
                cell.StyleIndex = value;
            }
        }
コード例 #22
0
        public void ShouldSetCells()
        {
            using (var ms = new MemoryStream())
            {
                using (var doc = SpreadsheetDocument.Create(ms, SpreadsheetDocumentType.Workbook, true))
                {
                    var sheet = SpreadsheetHelper.GetSheetData(doc, "Sheet3", createIfDoesntExists: true);

                    SpreadsheetHelper.SetValue(doc, null, "A", CellValues.SharedString, sheet, BaseAZ.Parse("A"), 5);
                    SpreadsheetHelper.SetValue(doc, null, "B", CellValues.SharedString, sheet, BaseAZ.Parse("C"), 5);
                    SpreadsheetHelper.SetValue(doc, null, "C", CellValues.SharedString, sheet, BaseAZ.Parse("E"), 5);
                    SpreadsheetHelper.SetValue(doc, null, "125", null, sheet, BaseAZ.Parse("A"), 3);
                    SpreadsheetHelper.SetValue(doc, null, "458", CellValues.SharedString, sheet, BaseAZ.Parse("C"), 3);
                    SpreadsheetHelper.SetValue(doc, null, "4.586", CellValues.SharedString, sheet, BaseAZ.Parse("E"), 3);
                    SpreadsheetHelper.SetValue(doc, null, "1", CellValues.Boolean, sheet, BaseAZ.Parse("A"), 1);
                    SpreadsheetHelper.SetValue(doc, null, "0", CellValues.Boolean, sheet, BaseAZ.Parse("C"), 1);
                    SpreadsheetHelper.SetValue(doc, null, "info", CellValues.SharedString, sheet, BaseAZ.Parse("E"), 1);

                    doc.Save();
                    doc.Dispose();
                }

                using (var doc = SpreadsheetDocument.Open(ms, true))
                {
                    var sheetData = SpreadsheetHelper.GetSheetData(doc, "Sheet3");

                    Assert.AreEqual("A", SpreadsheetHelper.GetValue(doc, sheetData, null, BaseAZ.Parse("A"), 5));
                    Assert.AreEqual("B", SpreadsheetHelper.GetValue(doc, sheetData, null, BaseAZ.Parse("C"), 5));
                    Assert.AreEqual("C", SpreadsheetHelper.GetValue(doc, sheetData, null, BaseAZ.Parse("E"), 5));
                    Assert.AreEqual("125", SpreadsheetHelper.GetValue(doc, sheetData, null, BaseAZ.Parse("A"), 3));
                    Assert.AreEqual("458", SpreadsheetHelper.GetValue(doc, sheetData, null, BaseAZ.Parse("C"), 3));
                    Assert.AreEqual("4.586", SpreadsheetHelper.GetValue(doc, sheetData, null, BaseAZ.Parse("E"), 3));
                    Assert.AreEqual("1", SpreadsheetHelper.GetValue(doc, sheetData, null, BaseAZ.Parse("A"), 1));
                    Assert.AreEqual("0", SpreadsheetHelper.GetValue(doc, sheetData, null, BaseAZ.Parse("C"), 1));
                    Assert.AreEqual("info", SpreadsheetHelper.GetValue(doc, sheetData, null, BaseAZ.Parse("E"), 1));
                }

                DumpGeneratedExcelFiles.Dump(ms);
            }
        }
コード例 #23
0
        public void ShouldCreateSheetData()
        {
            using (var ms = new MemoryStream())
            {
                using (var doc = SpreadsheetDocument.Create(ms, SpreadsheetDocumentType.Workbook, true))
                {
                    SpreadsheetHelper.GetSheetData(doc, "Sheet3", createIfDoesntExists: true);

                    doc.Save();
                    doc.Dispose();
                }

                using (var doc = SpreadsheetDocument.Open(ms, true))
                {
                    var sheetData = SpreadsheetHelper.GetSheetData(doc, "Sheet3");

                    Assert.IsNotNull(sheetData);

                    doc.Dispose();
                }

                DumpGeneratedExcelFiles.Dump(ms);
            }
        }
コード例 #24
0
        public void Import(string filename)
        {
            using (var helper = new SpreadsheetHelper(filename))
            {
                if (!helper.MoveWorksheet(sheetName))
                {
                    throw new ApplicationException("不正なテンプレートです。" + sheetName + "のシートがありません");
                }
                var worksheet = helper.CurrentSheet;

                using (var serverContext = ServerApplicationContext.CreateContext())
                {
                    var date   = (DateTime)helper.GetCellValue(startDateCell, CellValues.Date);
                    var userId = helper.GetCellValue(emailAddressCell) as string;
                    if (string.IsNullOrEmpty(userId))
                    {
                        throw new ApplicationException("ユーザが指定されていません");
                    }
                    var sb = new StringBuilder();
                    for (int rowIdx = startPos; rowIdx < startPos + 31; rowIdx++)
                    {
                        using (var workspace = serverContext.Application.CreateDataWorkspace())
                        {
                            try
                            {
                                string sickHoliday     = helper.GetCellValue(4, rowIdx) as string;
                                var    startTimeObject = helper.GetCellValue(9, rowIdx);
                                string startTime       = startTimeObject is DateTime ? ((DateTime)startTimeObject).ToString("HH:mm") : startTimeObject as string;
                                var    endTimeObject   = helper.GetCellValue(11, rowIdx);
                                string endTime         = endTimeObject is DateTime ? ((DateTime)endTimeObject).ToString("HH:mm") : endTimeObject as string;
                                var    item            = workspace.ApplicationData.WorkTimeSet.AddNew();
                                string remark          = helper.GetCellValue(16, rowIdx) as string;

                                if (string.IsNullOrEmpty(startTime) && string.IsNullOrEmpty(endTime) && string.IsNullOrEmpty(remark) && string.IsNullOrEmpty(sickHoliday))
                                {
                                    continue;
                                }

                                item.UserId     = userId;
                                item.SickHolidy = sickHoliday;
                                item.WorkDate   = date.AddDays(rowIdx - startPos);
                                item.StartTime  = startTime;
                                item.EndTime    = endTime;
                                item.Remark     = remark;
                                workspace.ApplicationData.SaveChanges();
                            }
                            catch (Microsoft.LightSwitch.ValidationException vex)
                            {
                                foreach (var error in vex.ValidationResults)
                                {
                                    sb.AppendLine(date.AddDays(rowIdx - startPos).ToString("d") + ":" + error.Message);
                                }
                            }
                        }
                    }
                    if (sb.Length > 0)
                    {
                        throw new ApplicationException(sb.ToString());
                    }
                }
            }
        }
コード例 #25
0
        public async Task <ActionResult> OrderActionNewReserva(int id, int status, int ot, int percent)
        {
            var order = await _orderService.FindAsync(id);

            order.Status   = status;
            order.OT       = ot;
            order.Modified = DateTime.Now;
            if (status == 2)
            {
                order.Percent = percent;
                int valor = Convert.ToInt32(order.Total.Value);
                int abono = (percent * valor) / 100;
                order.Abono = abono;
            }

            _orderService.Update(order);

            await _unitOfWorkAsync.SaveChangesAsync();

            var pasajero  = _aspNetUserService.Query(x => x.Id == order.UserReceiver).Select().FirstOrDefault();
            var propiedad = await _listingService.FindAsync(order.ListingID);

            var condominio = await _categoryService.FindAsync(propiedad.CategoryID);

            if (status == 2)
            {
                var emailorderquery = await _emailTemplateService.Query(x => x.Slug.ToLower() == "pagoabono").SelectAsync();

                var     templateorder = emailorderquery.Single();
                dynamic emailorder    = new Postal.Email("Email");
                emailorder.To               = pasajero.Email;
                emailorder.From             = CacheHelper.Settings.EmailAddress;
                emailorder.Subject          = templateorder.Subject;
                emailorder.Body             = templateorder.Body;
                emailorder.Name             = pasajero.FirstName + pasajero.LastName;
                emailorder.Adults           = order.Adults;
                emailorder.Children         = order.Children;
                emailorder.Rent             = order.Price;
                emailorder.CleanlinessPrice = propiedad.CleanlinessPrice;
                emailorder.Service          = order.Price * 0.04;
                emailorder.Total            = order.Total;
                emailorder.Address          = propiedad.Address;
                emailorder.Condominium      = condominio.Name;
                emailorder.Period           = string.Format("Desde el {0} hasta el {1}", order.FromDate.Value.ToShortDateString(), order.ToDate.Value.ToShortDateString());
                emailorder.Tarifa           = propiedad.Price;
                emailorder.Abono            = order.Abono;
                emailorder.Garantia         = propiedad.Warranty;
                emailorder.FromDate         = order.FromDate.Value.ToShortDateString();
                emailorder.ToDate           = order.ToDate.Value.ToShortDateString();
                emailorder.Id               = order.ListingID;
                emailorder.OT               = order.OT;
                emailorder.Percent          = order.Percent;
                //Falta agregar la Orden de trabajo
                EmailHelper.SendEmail(emailorder);
            }

            //Generar SpreadSheet
            SpreadsheetHelper.WriteOtOAuth(order, propiedad, pasajero);

            var result = new
            {
                Success = true,
                Message = "Hola"
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #26
0
        public void ShouldConvertSimpleLetterString(string columnString, int expectedResult)
        {
            var result = SpreadsheetHelper.ConvertColumnHeaderToNumber(columnString);

            Assert.Equal(expectedResult, result);
        }