Exemplo n.º 1
0
 public static bool IsRemoveItemRange(Cell cell, Range orderItemsRange)
 {
     return(IsSingleCellSelected(cell) &&
            cell.LeftColumnIndex > orderItemsRange.RightColumnIndex &&
            cell.LeftColumnIndex < orderItemsRange.RightColumnIndex + 4 &&
            cell.TopRowIndex >= orderItemsRange.TopRowIndex &&
            cell.TopRowIndex <= orderItemsRange.BottomRowIndex);
 }
 public static void UpdateProductPrice(Cell cell, OrderItem orderItem, DevExpress.Spreadsheet.Range orderItemRange)
 {
     if (CellsHelper.IsOrderItemProductCell(cell, orderItemRange))
     {
         orderItemRange[CellsHelper.GetOffset(CellsKind.UnitPrice)].Value = (double)orderItem.Product.SalePrice;
         orderItem.ProductPrice = orderItem.Product.SalePrice;
     }
 }
 public static void InitializeOrderItem(DevExpress.Spreadsheet.Range itemRange, OrderItem orderItem)
 {
     itemRange[CellsHelper.GetOffset(CellsKind.ProductDescription)].Value = orderItem.Product != null
         ? orderItem.Product.Name : string.Empty;
     itemRange[CellsHelper.GetOffset(CellsKind.Quantity)].Value  = orderItem.ProductUnits > 0 ? orderItem.ProductUnits : 1;
     itemRange[CellsHelper.GetOffset(CellsKind.UnitPrice)].Value = (double)orderItem.ProductPrice;
     itemRange[CellsHelper.GetOffset(CellsKind.Discount)].Value  = (double)orderItem.Discount;
 }
Exemplo n.º 4
0
 void AsyncUpdateSummaries(OrderItem orderItem, DevExpress.Spreadsheet.Range orderItemRange)
 {
     System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => {
         orderItem.Discount = (int)CellsHelper.GetOrderItemCellValue(CellsKind.Discount, orderItemRange, Invoice).NumericValue;
         orderItem.Total = (int)CellsHelper.GetOrderItemCellValue(CellsKind.Total, orderItemRange, Invoice).NumericValue;
         UpdateTotalValues();
     }));
 }
Exemplo n.º 5
0
        public static CellValue GetOrderItemCellValue(CellsKind cell, Range orderItemRange, Worksheet invoice)
        {
            int offset    = CellsHelper.GetOffset(cell);
            var cellRange = invoice.Range.FromLTRB(orderItemRange.LeftColumnIndex + offset,
                                                   orderItemRange.TopRowIndex, orderItemRange.LeftColumnIndex + offset, orderItemRange.BottomRowIndex);

            return(cellRange.Value);
        }
Exemplo n.º 6
0
        void UpdateOrderItem(Cell cell)
        {
            var   verticalOffset  = GetOrderItemOffset(cell);
            Range orderItemsRange = GetOrderItemsArea().Range;

            var orderItem      = actualOrderItems[verticalOffset];
            var orderItemRange = Invoice.Range.FromLTRB(orderItemsRange.LeftColumnIndex, orderItemsRange.TopRowIndex + verticalOffset,
                                                        orderItemsRange.RightColumnIndex, orderItemsRange.TopRowIndex + verticalOffset);

            OrderPropertiesHelper.UpdateProductUnits(orderItem, orderItemRange, Invoice);
            OrderPropertiesHelper.UpdateProduct(orderItem, CellsHelper.GetOrderItemCellValue(CellsKind.ProductDescription, orderItemRange, Invoice), source);
            OrderPropertiesHelper.UpdateProductPrice(cell, orderItem, orderItemRange);
            AsyncUpdateSummaries(orderItem, orderItemRange);
        }
Exemplo n.º 7
0
        private void initialsheet()
        {
            IWorkbook workbook = spreadsheetControl1.Document;
            Worksheet worksheet1;
            Worksheet worksheet2;
            var       sheets = workbook.Worksheets;


            if (workbook.Worksheets.Count < 3)
            {
                worksheet1 = workbook.Worksheets.Add("指标权重");

                //workbook.Worksheets[0].Visible = false;
                //workbook.Worksheets[1].Visible = false;

                // spreadsheetControl1.Options.TabSelector.Visibility = DevExpress.XtraSpreadsheet.SpreadsheetElementVisibility.Hidden;
                worksheet2 = workbook.Worksheets[1];
                int           j         = 0;
                List <string> para_name = new List <string>();
                while (worksheet2[0, j + 2].Value.IsEmpty == false & worksheet2[0, j + 2].Value != "评价结果" & worksheet2[0, j + 2].Value.ToString() != "综合得分")
                {
                    para_name.Add(worksheet2[0, j + 2].Value.ToString());
                    j++;
                }
                int countcol = j;

                for (int i = 0; i < para_name.Count; i++)
                {
                    worksheet1.Cells[0, i + 1].Value = para_name[i];
                    worksheet1.Cells[i + 1, 0].Value = para_name[i];
                }
                worksheet1.Cells[para_name.Count + 1, 0].Value = "指标权重";
                DevExpress.Spreadsheet.Range range = worksheet1.Range.FromLTRB(0, 0, para_name.Count + 1, 0);
                range.Fill.BackgroundColor = Color.FromArgb(217, 217, 217);
                for (int i = 0; i < para_name.Count + 1; i++)
                {
                    range = worksheet1.Range.FromLTRB(i, i, i, para_name.Count + 1);
                    range.Fill.BackgroundColor = Color.FromArgb(217, 217, 217);
                }
                worksheet1.Range["A1:Z1"].ColumnWidthInCharacters = 12;
                worksheet1.Range["A1:A500"].RowHeight             = 80;
            }
            else
            {
                worksheet1 = workbook.Worksheets[2];
                workbook.Worksheets.ActiveWorksheet = workbook.Worksheets[2];
            }
        }
            object[,] ConvertRefParameter(DevExpress.Spreadsheet.Range parameter)
            {
                int height = parameter.RowCount;
                int width  = parameter.ColumnCount;

                object[,] result = (object[, ])Array.CreateInstance(typeof(object), new[] { height, width }, new[] { 1, 1 });
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        DevExpress.Spreadsheet.CellValue value = parameter[i, j].Value;
                        result[i + 1, j + 1] = ConvertParameter(value);
                    }
                }
                return(result);
            }
Exemplo n.º 9
0
        void AddOrderItemToSheet(OrderItem orderItem)
        {
            var invoiceItemsArea = GetOrderItemsArea();
            int rowIndex         = invoiceItemsArea.Range.BottomRowIndex;

            Invoice.Rows.Insert(rowIndex);
            Invoice.Rows[rowIndex].Height     = Invoice.Rows[rowIndex - 1].Height;
            Invoice.Rows[rowIndex + 1].Height = Invoice.Rows[rowIndex].Height;
            DevExpress.Spreadsheet.Range range     = invoiceItemsArea.Range;
            DevExpress.Spreadsheet.Range itemRange = Invoice.Range.FromLTRB(range.LeftColumnIndex, range.BottomRowIndex, range.RightColumnIndex, range.BottomRowIndex);
            if (range.RowCount == 1)
            {
                Invoice["K24"].FormulaInvariant = "=SUM(K22:K23)";
                invoiceItemsArea.Range          = Invoice.Range.FromLTRB(range.LeftColumnIndex, range.TopRowIndex - 1, range.RightColumnIndex, range.BottomRowIndex)
                                                  .GetRangeWithAbsoluteReference();
                if (AllowChangeOrder())
                {
                    UpdateOrderItemEditors();
                }
            }
            CellsHelper.CopyOrderItemRange(itemRange);
            OrderPropertiesHelper.InitializeOrderItem(itemRange, orderItem);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 生成表格
        /// </summary>
        public void DoReport()
        {
            CommonClass common = new CommonClass();
            ConnectDB   db     = new ConnectDB();
            DataTable   DT     = db.GetDataBySql("select GLDWNAME from GISDATA_GLDW where GLDW = '" + common.GetConfigValue("GLDW") + "'");
            DataRow     dr     = DT.Select(null)[0];
            string      path   = common.GetConfigValue("SAVEDIR") + "\\" + dr["GLDWNAME"].ToString() + "\\表格";

            //string path = @"D:\report\";
            if (Directory.Exists(path) == false)
            {
                Directory.CreateDirectory(path);
            }
            int[]     selectRows = this.gridView1.GetSelectedRows();
            DataTable dtDs       = new DataTable();

            foreach (int itemRow in selectRows)
            {
                mydelegate = new myDelegate(setPos);
                Thread myThread = new Thread((ThreadStart)(delegate()
                {
                    this.BeginInvoke(mydelegate, new object[] { itemRow });
                }));
                myThread.IsBackground = true;
                myThread.Start();
                //Thread MyThread = new Thread(new ParameterizedThreadStart(setPos));
                //MyThread.IsBackground = true;
                //MyThread.Start(itemRow);
                DataRow  row           = this.gridView1.GetDataRow(itemRow);
                String   reportType    = row["REPORTTYPE"].ToString();
                String   sheetname     = row["SHEETNAME"].ToString();
                String   sqlstr        = row["SQLSTR"].ToString();
                String   rowname       = row["ROWNAME"].ToString().Trim();
                String   columnsname   = row["COLUMNSNAME"].ToString().Trim();
                String   ValueStr      = row["VALUESTRING"].ToString().Trim();
                String   sortfield     = row["SORTFIELD"].ToString().Trim();
                string[] dataSourceArr = row["DATASOURCE"].ToString().Split(',');

                SpreadsheetControl sheet = new SpreadsheetControl();
                Spread.IWorkbook   book  = sheet.Document;
                book.LoadDocument(Application.StartupPath + "\\Report\\" + row["REPORTMOULD"].ToString(), Spread.DocumentFormat.OpenXml);
                if (reportType == "任务完成统计表")
                {
                    wwcxmTable = new DataTable();
                    string    gldw     = common.GetConfigValue("GLDW") == "" ? "520121" : common.GetConfigValue("GLDW");
                    DataTable dtTaskDb = db.GetDataBySql("select YZLGLDW,YZLFS,ZCSBND,XMMC,RWMJ from GISDATA_TASK where YZLGLDW = '" + gldw + "'");
                    dtTaskDb.TableName = "GISDATA_TASK";
                    DataTable dtTask = common.TranslateDataTable(dtTaskDb);
                    DataRow[] drTask = dtTask.Select(null);
                    dtTask.Columns.Add("SBMJ");
                    dtDs.Columns.Add("YZLGLDW");
                    dtDs.Columns.Add("YZLFS");
                    dtDs.Columns.Add("ZCSBND");
                    dtDs.Columns.Add("XMMC");
                    dtDs.Columns.Add("RWMJ");
                    dtDs.Columns.Add("SBMJ");

                    wwcxmTable.Columns.Add("YZLFS");
                    wwcxmTable.Columns.Add("ZCSBND");
                    wwcxmTable.Columns.Add("XMMC");
                    wwcxmTable.Columns.Add("RWMJ");
                    wwcxmTable.Columns.Add("SBMJ");

                    DataTable dt = new DataTable();
                    for (int i = 0; i < dataSourceArr.Length; i++)
                    {
                        DataTable itemDt = common.GetTableByName(dataSourceArr[i].Trim());
                        //DataTable itemDt = ToDataTable(table);
                        dt.Merge(itemDt);
                    }

                    for (int i = 0; i < drTask.Length; i++)
                    {
                        DataRow rowItem = drTask[i];
                        string  zcsbnd  = rowItem["ZCSBND"].ToString();
                        gldw = rowItem["YZLGLDW"].ToString();
                        string yzlfs = rowItem["YZLFS"].ToString();
                        string xmmc  = rowItem["XMMC"].ToString();
                        string sbmj  = "";

                        var query = from t in dt.AsEnumerable()
                                    where (t.Field <string>("YZLGLDW") == gldw && t.Field <string>("ZCSBND") == zcsbnd && t.Field <string>("YZLFS") == yzlfs && t.Field <string>("XMMC") == xmmc)
                                    group t by new { t1 = t.Field <string>("YZLGLDW"), t2 = t.Field <string>("ZCSBND"), t3 = t.Field <string>("YZLFS"), t4 = t.Field <string>("XMMC") } into m
                            select new
                        {
                            gldwItem   = m.Key.t1,
                            zcsbndItem = m.Key.t2,
                            yzlfsItem  = m.Key.t3,
                            xmmcItem   = m.Key.t4,
                            sbmjItem   = m.Sum(n => Convert.ToDouble(n["SBMJ"]))
                        };
                        if (query.ToList().Count > 0)
                        {
                            query.ToList().ForEach(q =>
                            {
                                sbmj = q.sbmjItem.ToString();
                            });
                        }
                        rowItem["SBMJ"] = sbmj == "" ? "0" : sbmj;
                        if (rowItem["SBMJ"].ToString() != rowItem["RWMJ"].ToString())
                        {
                            wwcxmTable.ImportRow(rowItem);
                        }
                        dtDs.ImportRow(rowItem);
                    }
                    book.MailMergeDataSource = dtDs;
                    Spread.IWorkbook resultBook = book.GenerateMailMergeDocuments()[0];
                    string           time       = DateTime.Now.ToString("yyyyMMddHHmmss");
                    if (resultBook != null)
                    {
                        using (MemoryStream result = new MemoryStream())
                        {
                            resultBook.SaveDocument(path + "\\" + row["REPORTNAME"].ToString() + time + ".xlsx");
                            result.Seek(0, SeekOrigin.Begin);
                        }
                    }
                }
                else if (reportType == "透视表")
                {
                    DataTable dt = new DataTable();
                    for (int i = 0; i < dataSourceArr.Length; i++)
                    {
                        DataTable itemDt = common.GetTableByName(dataSourceArr[i].Trim());
                        //DataTable itemDt = ToDataTable(table);
                        dt.Merge(itemDt);
                    }
                    dt.DefaultView.Sort = sortfield;
                    ConvertPivotTable conver  = new ConvertPivotTable();
                    DataTable         dtPivot = conver.CreatePivotTable(dt, columnsname.Trim(), "SBMJ", "", rowname.Trim());

                    Spread.Worksheet      Spreadsheet   = book.Worksheets[sheetname];
                    Model.DocumentModel   documentModel = new Model.DocumentModel();
                    FileInfo              xlxsFile      = new FileInfo(Application.StartupPath + "\\Report\\" + row["REPORTMOULD"].ToString());
                    System.IO.Stream      stream        = xlxsFile.OpenRead();
                    Spread.DocumentFormat format        = documentModel.AutodetectDocumentFormat(xlxsFile.Name);
                    documentModel.LoadDocument(stream, format, string.Empty);

                    MailMergeOptions option = new MailMergeOptions(documentModel);

                    Model.CellRangeBase detail = option.DetailRange;
                    Model.CellRangeBase header = option.HeaderRange;

                    IEnumerable <Spread.Cell> dynamiccolArr   = Spreadsheet.Search("=DYNAMICCOL(\"" + columnsname + "\")");
                    IEnumerable <Spread.Cell> dynamicfieldArr = Spreadsheet.Search("=DYNAMICFIELD(\"" + columnsname + "\")");
                    Spread.Cell dynamiccol = null;
                    foreach (Spread.Cell str in dynamiccolArr)
                    {
                        dynamiccol = str;
                        break;
                    }
                    Spread.Cell dynamicFiled = null;

                    foreach (Spread.Cell str in dynamicfieldArr)
                    {
                        dynamicFiled = str;
                        break;
                    }
                    int ColumnIndexItem = 0;
                    for (int i = 0; i < dtPivot.Columns.Count; i++)
                    {
                        DataColumn itemColumn = dtPivot.Columns[i];
                        if (itemColumn.Namespace == columnsname)
                        {
                            Spread.Cell rangeHeader = Spreadsheet.Cells[dynamiccol.RowIndex, dynamiccol.ColumnIndex + ColumnIndexItem];
                            Spread.Cell rangeDetail = Spreadsheet.Cells[dynamicFiled.RowIndex, dynamiccol.ColumnIndex + ColumnIndexItem];
                            rangeHeader.CopyFrom(dynamiccol);
                            rangeDetail.CopyFrom(dynamicFiled);
                            rangeHeader.Value = itemColumn.Caption.ToString();
                            rangeDetail.Calculate();
                            rangeHeader.Calculate();
                            rangeDetail.Value   = "=FIELD(\"" + itemColumn.ColumnName.ToString() + "\")";
                            rangeDetail.Formula = "=FIELD(\"" + itemColumn.ColumnName.ToString() + "\")";
                            ColumnIndexItem++;
                        }
                    }

                    //标题range
                    if (Spreadsheet.DefinedNames.GetDefinedName("TITLESTRING") != null)
                    {
                        Spread.Range       titleRange        = Spreadsheet.DefinedNames.GetDefinedName("TITLESTRING").Range;
                        Model.CellPosition TitleStarPosition = new Model.CellPosition(titleRange.LeftColumnIndex, titleRange.TopRowIndex);
                        Model.CellPosition TitleEndPosition  = new Model.CellPosition(titleRange.RightColumnIndex + ColumnIndexItem - 1, titleRange.BottomRowIndex);
                        Model.CellRange    newTitle          = new Model.CellRange(header.Worksheet, TitleStarPosition, TitleEndPosition);
                        titleRange = Spreadsheet.Range[newTitle.ToString()];
                        Spreadsheet.MergeCells(titleRange);
                    }

                    //单位Range
                    if (Spreadsheet.DefinedNames.GetDefinedName("UNITSTRING") != null)
                    {
                        Spread.Range       unitRange        = Spreadsheet.DefinedNames.GetDefinedName("UNITSTRING").Range;
                        Model.CellPosition UnitStarPosition = new Model.CellPosition(unitRange.LeftColumnIndex, unitRange.TopRowIndex);
                        Model.CellPosition UnitEndPosition  = new Model.CellPosition(unitRange.RightColumnIndex + ColumnIndexItem - 1, unitRange.BottomRowIndex);
                        Model.CellRange    newUnit          = new Model.CellRange(header.Worksheet, UnitStarPosition, UnitEndPosition);
                        unitRange = Spreadsheet.Range[newUnit.ToString()];
                        Spreadsheet.MergeCells(unitRange);
                        Spread.Style unitStyle = unitRange.Style;
                        unitStyle.Alignment.Horizontal = Spread.SpreadsheetHorizontalAlignment.Right;
                    }

                    //Detail Range
                    Model.CellRange newDetail   = new Model.CellRange(header.Worksheet, detail.TopLeft.Column, detail.TopLeft.Row, detail.TopRight.Column + ColumnIndexItem, detail.BottomRight.Row);
                    Spread.Range    detailRange = Spreadsheet.Range[newDetail.ToString()];
                    Spreadsheet.DefinedNames.GetDefinedName("DETAILRANGE").Range = detailRange;
                    //Header Range
                    Model.CellRange newHeader   = new Model.CellRange(header.Worksheet, header.TopLeft.Column, header.TopLeft.Row, header.TopRight.Column + ColumnIndexItem, header.BottomRight.Row);
                    Spread.Range    headerRange = Spreadsheet.Range[newHeader.ToString()];
                    Spreadsheet.DefinedNames.GetDefinedName("HEADERRANGE").Range = headerRange;



                    string time = DateTime.Now.ToString("yyyyMMddHHmmss");
                    book.MailMergeDataSource = dtPivot;
                    Spread.IWorkbook resultBook = book.GenerateMailMergeDocuments()[0];
                    if (resultBook != null)
                    {
                        using (MemoryStream result = new MemoryStream())
                        {
                            resultBook.SaveDocument(path + "\\" + row["REPORTNAME"].ToString() + time + ".xlsx");
                            result.Seek(0, SeekOrigin.Begin);
                            SpreadsheetControl mergesheet = new SpreadsheetControl();
                            Spread.IWorkbook   mergebook  = mergesheet.Document;
                            mergebook.LoadDocument(path + "\\" + row["REPORTNAME"].ToString() + time + ".xlsx", Spread.DocumentFormat.OpenXml);
                            Spread.Worksheet MergeSpreadsheet = mergebook.Worksheets[sheetname];
                            int TableRowCnts = detail.TopLeft.Row + dtPivot.Rows.Count;
                            int tmpA;
                            int tmpB;
                            var PerTxt      = "";
                            var CurTxt      = "";
                            var groupPerTxt = "";
                            var groupCurTxt = "";
                            for (int i = detail.TopRight.Column; i > 0; i--)
                            {
                                PerTxt = "";
                                tmpA   = 1;
                                tmpB   = 0;
                                for (int j = detail.TopLeft.Row; j <= TableRowCnts; j++)
                                {
                                    groupCurTxt = "";
                                    if (j == TableRowCnts)
                                    {
                                        CurTxt = "";
                                    }
                                    else
                                    {
                                        CurTxt = MergeSpreadsheet.GetCellValue(i - 1, j).ToString();
                                    }
                                    for (int k = i - 1; k > 0; k--)
                                    {
                                        groupCurTxt += MergeSpreadsheet.GetCellValue(k - 1, j).ToString();
                                    }
                                    if (PerTxt == CurTxt && groupCurTxt == groupPerTxt)
                                    {
                                        tmpA += 1;
                                    }
                                    else
                                    {
                                        tmpB += tmpA;
                                        if (tmpA > 1)
                                        {
                                            Model.CellRange MergePos   = new Model.CellRange(newDetail.Worksheet, i - 1, j - tmpA, i - 1, j - 1);
                                            Spread.Range    MergeRange = MergeSpreadsheet.Range[MergePos.ToString()];
                                            MergeSpreadsheet.MergeCells(MergeRange);
                                        }
                                        tmpA = 1;
                                    }
                                    PerTxt      = CurTxt;
                                    groupPerTxt = groupCurTxt;
                                }
                            }
                            mergebook.SaveDocument(path + "\\" + row["REPORTNAME"].ToString() + time + ".xlsx");
                        }
                    }
                }
                else
                {
                    DataTable dt = new DataTable();
                    for (int i = 0; i < dataSourceArr.Length; i++)
                    {
                        DataTable itemDt = common.GetTableByName(dataSourceArr[i].Trim());
                        //DataTable itemDt = ToDataTable(table);
                        dt.Merge(itemDt);
                    }
                    //dtDs = common.TranslateDataTable(dt);
                    book.MailMergeDataSource = dt;
                    Spread.IWorkbook resultBook = book.GenerateMailMergeDocuments()[0];
                    string           time       = DateTime.Now.ToString("yyyyMMddHHmmss");
                    if (resultBook != null)
                    {
                        using (MemoryStream result = new MemoryStream())
                        {
                            resultBook.SaveDocument(path + "\\" + row["REPORTNAME"].ToString() + time + ".xlsx");
                            result.Seek(0, SeekOrigin.Begin);
                        }
                    }
                }
                row["STATE"] = "完成";
            }
        }
 public static void UpdateProductUnits(OrderItem orderItem, DevExpress.Spreadsheet.Range orderItemRange, Worksheet invoice)
 {
     orderItem.ProductUnits = (int)CellsHelper.GetOrderItemCellValue(CellsKind.Quantity, orderItemRange, invoice).NumericValue;
 }
Exemplo n.º 12
0
 public static bool IsOrderItemProductCell(Cell cell, Range orderItemRange)
 {
     return(cell.LeftColumnIndex - orderItemRange.LeftColumnIndex == CellsHelper.FindCell(CellsKind.ProductDescription).Offset);
 }
Exemplo n.º 13
0
        public static void CopyOrderItemRange(Range itemRange)
        {
            Range range = itemRange.Offset(-1, 0);

            range.CopyFrom(itemRange, PasteSpecial.All, true);
        }
Exemplo n.º 14
0
        private void sbtnGetInfo_Click(object sender, EventArgs e)
        {
            IList <DevExpress.Spreadsheet.Range> selectedRange = spreadsheetControl1.GetSelectedRanges();

            DevExpress.Spreadsheet.Range curentRange = selectedRange[0];
            if (!(curentRange.TopRowIndex == curentRange.BottomRowIndex && curentRange.LeftColumnIndex == curentRange.RightColumnIndex))
            {
                //MessageBox.Show(curentRange.TopRowIndex.ToString());
                SearchOptions option = new SearchOptions();
                option.SearchBy = SearchBy.Columns;
                option.SearchIn = SearchIn.Values;
                option.MatchEntireCellContents = true;
                IEnumerable <Cell> searchResult;
                // Tìm cột MSNV
                searchResult = curentRange.Search("MSNV", option);
                if (searchResult == null)
                {
                    MessageBox.Show("Không tìm thấy cột MSNV trong vùng dữ liệu được chọn");
                    return;
                }
                int colMSNV = searchResult.First().LeftColumnIndex;
                // Dòng dữ liệu đầu tiên
                int firstRow = searchResult.First().TopRowIndex + 1;
                // Tìm cột Ngày hiệu lực HĐ
                searchResult = curentRange.Search("Ngày hiệu lực HĐ", option);
                if (searchResult == null)
                {
                    MessageBox.Show("Không tìm thấy cột Ngày hiệu lực HĐ trong vùng dữ liệu được chọn");
                    return;
                }
                int colContactFromDate = searchResult.First().LeftColumnIndex;
                // Tìm cột Ngày hết hiệu lực HĐ
                searchResult = curentRange.Search("Ngày hết hiệu lực HĐ", option);
                if (searchResult == null)
                {
                    MessageBox.Show("Không tìm thấy cột Ngày hết hiệu lực HĐ trong vùng dữ liệu được chọn");
                    return;
                }
                int colContactToDate = searchResult.First().LeftColumnIndex;
                // Dòng và cột cuối của Range
                int lastcol = curentRange.RightColumnIndex;
                int lastrow = curentRange.BottomRowIndex;
                if (lastrow < firstRow)
                {
                    MessageBox.Show("Vùng chọn không có dữ liệu");
                    return;
                }
                HREntities hr = new HREntities();
                //string filesource = @"\\10.100.8.108\phanbay\doantv\ddtvvfp6\solieu\lbaytv2.dbf";
                string filedes = @"F:\temp\lbaytv2.dbf";
                //System.IO.File.Copy(filesource, filedes, true);
                FileStream lb = new FileStream(filedes, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                //BufferedStream bufflb = new BufferedStream(lb);
                //NDbfReader.Table lbtv = NDbfReader.Table.Open(lb);

                DataTable lbtv = NDbfReader.Table.Open(lb).AsDataTable();

                //var kbtv = lbtv.AsEnumerable().Select(u => new { code_tv = u.Field<string>("code_tv"),loai=u.Field<string>("loai"),start_date=u.Field<DateTime>("start_date"),end_date=u.Field<DateTime>("end_date")}).Where(x=>x.loai!="FLY");
                //DateTime d1, d2;
                //string codetv;
                //int i=firstRow;
                //do {
                //    codetv = curentRange[i, colMSNV].Value.TextValue;
                //    d1 = curentRange[i, colContactFromDate].Value.DateTimeValue;
                //    d2 = curentRange[i, colContactToDate].Value.DateTimeValue;
                //    var tvoff = kbtv.Where(x => x.code_tv == codetv && ((x.start_date >= d1 && x.start_date <= d2) || (x.end_date >= d1 && x.end_date <= d2) || (d1>=x.start_date && d1<=x.end_date) || (d2>=x.start_date && d2<=x.end_date)));
                //    i++;
                //} while (i<=lastrow);
                MessageBox.Show(curentRange.RowCount.ToString());
                lb.Dispose();
                hr.Dispose();
            }
            else
            {
                MessageBox.Show("Vui lòng chọn vùng dữ liệu");
            }
        }
Exemplo n.º 15
0
        private void btncal_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            List <SortField> fields     = new List <SortField>();
            IWorkbook        workbook   = spreadsheetControl1.Document;
            Worksheet        worksheet0 = workbook.Worksheets[0]; //井位信息
            Worksheet        worksheet1 = workbook.Worksheets[1]; //井完整性评价
            Worksheet        worksheet2 = workbook.Worksheets[3]; //权重
            // First sorting field. First column (offset = 0) will be sorted using ascending order.
            SortField sortField1 = new SortField();

            sortField1.ColumnOffset = 0;
            sortField1.Comparer     = worksheet1.Comparers.Ascending;
            fields.Add(sortField1);

            // Second sorting field. Second column (offset = 1) will be sorted using ascending order.
            SortField sortField2 = new SortField();

            sortField2.ColumnOffset = 1;
            sortField2.Comparer     = worksheet1.Comparers.Ascending;
            fields.Add(sortField2);

            // Sort the range by sorting fields.
            // A rectangular range whose left column index is 0, top row index is 0,
            // right column index is 3 and bottom row index is 2. This is the A1:D3 cell range.
            int[] datanum = new int[2];
            datacount(datanum, worksheet1);
            DevExpress.Spreadsheet.Range range = worksheet1.Range.FromLTRB(0, 1, datanum[1], datanum[0]);
            worksheet1.Sort(range, fields);
            List <double>   welllocationx = new List <double>();
            List <double>   welllocationy = new List <double>();
            List <double[]> getDatasource = new List <double[]>();

            wellname          = new List <string>();   //井完整性的井名
            DataTimesource    = new List <DateTime>(); //井完整性的时间
            resultlistfen     = new List <double>();   //井完整性的结果
            resultlistfendraw = new List <double>();   //用于画结果图的评价结果,主要是用时间筛选
            wellnamedraw      = new List <string>();   //用于画结果图的井名
            List <double> result       = new List <double>();
            List <double> weightData   = new List <double>();
            List <string> wellfullname = new List <string>();
            int           countcol     = importdata(getDatasource, DataTimesource, wellname, worksheet1); //井完整性评价

            importdata(weightData, worksheet2);                                                           //权重
            importdata(welllocationx, welllocationy, wellfullname, worksheet0);                           //井坐标
            List <double> topten = new List <double>();

            for (int i = 0; i < getDatasource.Count; i++)
            {
                List <double> tempdata = new List <double>();
                for (int j = 0; j < countcol; j++)
                {
                    tempdata.Add(getDatasource[i][j]);
                }
                tempdata.Sort();
                topten.Add(tempdata[(int)(tempdata.Count * 0.1)]);
            }
            for (int i = 0; i < getDatasource.Count; i++)
            {
                double temp  = 0;
                double temp2 = 0;
                for (int j = 0; j < countcol; j++)
                {
                    temp = temp + getDatasource[i][j] * weightData[j];
                }

                if (temp < 6)
                {
                    temp2 = 0; worksheet1.Cells[i + 1, countcol + 3].Value = "安全";
                }
                else if (temp < 7)
                {
                    temp2 = 1; worksheet1.Cells[i + 1, countcol + 3].Value = "较安全";
                }
                else if (temp < 8)
                {
                    temp2 = 2; worksheet1.Cells[i + 1, countcol + 3].Value = "中等";
                }
                else if (temp < 9)
                {
                    temp2 = 3; worksheet1.Cells[i + 1, countcol + 3].Value = "较危险";
                    string ss = "";
                    for (int j = 0; j < countcol; j++)
                    {
                        if (getDatasource[i][j] > topten[j])
                        {
                            ss = "2";
                        }
                    }
                }
                else
                {
                    temp2 = 4; worksheet1.Cells[i + 1, countcol + 3].Value = "危险";
                }
                resultlistfen.Add(temp2);
                worksheet1.Cells[i + 1, countcol + 2].Value = temp;
                //worksheet2.Visible = false;
            }
            worksheet1.Cells[0, countcol + 2].Value = "综合得分";
            worksheet1.Cells[0, countcol + 3].Value = "评价结果";


            listdate = DataTimesource.Distinct().ToList();

            for (int i = 0; i < listdate.Count; i++)
            {
                (timeselect.Edit as RepositoryItemComboBox).Items.Add(listdate[i].ToShortDateString());
            }
            timeselect.EditValue = (timeselect.Edit as RepositoryItemComboBox).Items[0];
            adddraw(wellfullname, welllocationx, welllocationy);
            adddraw2(listdate[0].ToShortDateString() + "井筒完整性评价结果图");
            //ComboBoxproperties.Items.AddRange
            for (int i = 0; i < DataTimesource.Count; i++)
            {
                if (DataTimesource[i] == listdate[0])
                {
                    resultlistfendraw.Add(resultlistfen[i]); // = new List<double>();//用于画结果图的评价结果,主要是用时间筛选
                    wellnamedraw.Add(wellname[i]);           // = new List<string>();//用于画结果图的井名
                }
            }
        }
Exemplo n.º 16
0
        private void sbtnGetInfo_Click(object sender, EventArgs e)
        {
            IList <DevExpress.Spreadsheet.Range> selectedRange = spreadsheetControl1.GetSelectedRanges();

            DevExpress.Spreadsheet.Range curentRange = selectedRange[0];
            if (!(curentRange.TopRowIndex == curentRange.BottomRowIndex && curentRange.LeftColumnIndex == curentRange.RightColumnIndex))
            {
                //MessageBox.Show(curentRange.TopRowIndex.ToString());
                SearchOptions option = new SearchOptions();
                option.SearchBy = SearchBy.Columns;
                option.SearchIn = SearchIn.Values;
                option.MatchEntireCellContents = true;
                option.MatchCase = false;
                IEnumerable <Cell> searchResult;
                #region Tìm các cột
                // Tìm cột Crew ID
                searchResult = curentRange.Search("CREW ID", option);
                if (searchResult.Count() == 0)
                {
                    searchResult = curentRange.Search("CREWID", option);
                    if (searchResult.Count() == 0)
                    {
                        MessageBox.Show("Không tìm thấy cột Crew ID trong vùng dữ liệu được chọn");
                        return;
                    }
                }
                int colcrewid   = searchResult.First().LeftColumnIndex;
                int colflightid = colcrewid + 1;
                int colnote     = colcrewid + 2;
                // Dòng dữ liệu đầu tiên
                int firstRow = searchResult.First().TopRowIndex + 1;
                curentRange.Worksheet.Cells[firstRow - 1, colflightid].Value = "FLight ID";
                curentRange.Worksheet.Cells[firstRow - 1, colnote].Value     = "Note";
                curentRange.Worksheet.Cells[firstRow - 1, colnote + 1].Value = "Database";
                int colds, cols;
                colds = colnote + 2;
                cols  = colds + 2;
                //curentRange.Worksheet.Cells[firstRow - 1, colds].Value = "DS ID";
                //curentRange.Worksheet.Cells[firstRow - 1, colds+1].Value = "DS Name";
                //curentRange.Worksheet.Cells[firstRow - 1, cols].Value = "S ID";
                //curentRange.Worksheet.Cells[firstRow - 1, cols + 1].Value = "S Name";
                // Tìm cột Flight Date
                searchResult = curentRange.Search("Flight Date", option);
                if (searchResult.Count() == 0)
                {
                    searchResult = curentRange.Search("FlightDate", option);
                    if (searchResult.Count() == 0)
                    {
                        MessageBox.Show("Không tìm thấy cột Flight Date trong vùng dữ liệu được chọn");
                        return;
                    }
                }
                int colfltdate = searchResult.First().LeftColumnIndex;

                // Tìm cột Route
                searchResult = curentRange.Search("Route", option);
                if (searchResult.Count() == 0)
                {
                    MessageBox.Show("Không tìm thấy cột Route trong vùng dữ liệu được chọn");
                    return;
                }
                int colroute = searchResult.First().LeftColumnIndex;

                // Tìm cột FlightNo Flight No
                searchResult = curentRange.Search("FlightNo.", option);
                if (searchResult.Count() == 0)
                {
                    searchResult = curentRange.Search("Flight No.", option);
                    if (searchResult.Count() == 0)
                    {
                        MessageBox.Show("Không tìm thấy cột FlightNo trong vùng dữ liệu được chọn");
                        return;
                    }
                }
                int colfltno = searchResult.First().LeftColumnIndex;

                // Tìm cột CREW
                searchResult = curentRange.Search("CREW", option);
                if (searchResult.Count() == 0)
                {
                    searchResult = curentRange.Search("CREW NAME", option);
                    if (searchResult.Count() == 0)
                    {
                        MessageBox.Show("Không tìm thấy cột CREW trong vùng dữ liệu được chọn");
                        return;
                    }
                }
                int colcrew = searchResult.First().LeftColumnIndex;

                // Tìm cột KPT Revenue

                searchResult = curentRange.Search("KPT \nRevenue", option);
                if (searchResult.Count() == 0)
                {
                    searchResult = curentRange.Search("KPT\n Revenue", option);
                    if (searchResult.Count() == 0)
                    {
                        searchResult = curentRange.Search("KPT\nRevenue", option);
                        if (searchResult.Count() == 0)
                        {
                            MessageBox.Show("Không tìm thấy cột KPT Revenue trong vùng dữ liệu được chọn");
                            return;
                        }
                    }
                }
                int colrevenue = searchResult.First().LeftColumnIndex;

                // Tìm cột Discrepancy
                searchResult = curentRange.Search("Discrepancy", option);
                if (searchResult.Count() == 0)
                {
                    MessageBox.Show("Không tìm thấy cột Discrepancy trong vùng dữ liệu được chọn");
                    return;
                }
                int coldiscrepancy = searchResult.First().LeftColumnIndex;

                // Tìm cột Cashier Collected
                //string test = curentRange.Worksheet.Cells[1, 4].Value.ToString();
                searchResult = curentRange.Search("Cashier\n Collected", option);
                if (searchResult.Count() == 0)
                {
                    searchResult = curentRange.Search("Cashier \nCollected", option);
                    if (searchResult.Count() == 0)
                    {
                        searchResult = curentRange.Search("Cashier\nCollected", option);
                        if (searchResult.Count() == 0)
                        {
                            MessageBox.Show("Không tìm thấy cột Cashier Collected trong vùng dữ liệu được chọn");
                            return;
                        }
                    }
                }
                int colcashier = searchResult.First().LeftColumnIndex;

                // Tìm cột Card Settlement
                searchResult = curentRange.Search("Card \nSettlement", option);
                if (searchResult.Count() == 0)
                {
                    searchResult = curentRange.Search("Card\n Settlement", option);
                    if (searchResult.Count() == 0)
                    {
                        searchResult = curentRange.Search("Card\nSettlement", option);
                        if (searchResult.Count() == 0)
                        {
                            MessageBox.Show("Không tìm thấy cột Card Settlement trong vùng dữ liệu được chọn");
                            return;
                        }
                    }
                }
                int colcard = searchResult.First().LeftColumnIndex;

                // Tìm cột REMARK
                searchResult = curentRange.Search("REMARK", option);
                if (searchResult.Count() == 0)
                {
                    searchResult = curentRange.Search("REMARKS", option);
                    if (searchResult.Count() == 0)
                    {
                        MessageBox.Show("Không tìm thấy cột REMARK trong vùng dữ liệu được chọn");
                        return;
                    }
                }
                int colremark = searchResult.First().LeftColumnIndex;
                #endregion
                // Dòng và cột cuối của Range
                int lastcol = curentRange.RightColumnIndex;
                int lastrow = curentRange.BottomRowIndex;
                if (lastrow < firstRow)
                {
                    MessageBox.Show("Vùng chọn không có dữ liệu");
                    return;
                }
                HREntities    hr = new HREntities();
                ERMSEntities1 cb = new ERMSEntities1();

                //string filesource = @"\\10.100.8.108\phanbay\doantv\ddtvvfp6\solieu\lbaytv2.dbf";
                string     manv, hoten, tentv, route, flyno, remark, nametv = "";
                double     Discrepancy, KPTRevenue, CashierCollected, CardSettlement;
                DateTime   flydate;
                int        first_space, second_space, tt_ten, id_cb = -1;
                List <int> lstflightID = new List <int>();
                bool       flag_add;
                try {
                    for (int i = firstRow; i <= lastrow; i++)
                    {
                        flag_add = false;
                        var codetv = curentRange.Worksheet.Cells[i, colcrewid].Value;
                        if (!codetv.IsEmpty)
                        {
                            manv  = codetv.ToString().PadLeft(4, '0');
                            tentv = curentRange.Worksheet.Cells[i, colcrew].Value.ToString();
                        }
                        #region Tìm Crewid
                        else //Tìm Manv trong nhân sự dựa theo tên
                        {
                            tentv = curentRange.Worksheet.Cells[i, colcrew].Value.ToString().Trim();
                            manv  = "";
                            //Có khoảng trắng có thể là tên có số hoặc cả họ tên
                            if (tentv.Contains(" "))
                            {
                                first_space  = tentv.IndexOf(" ");
                                second_space = tentv.IndexOf(" ", first_space + 1);
                                if (second_space < 0) // Chỉ một khoản trằn có thể là tên và số trùng tên. Tìm trong Nhân sự theo hướng đó.
                                {
                                    var ns = hr.HoSoGocs.Where(x => x.Tenkd.Trim().ToUpper() == tentv.Trim().ToUpper()).FirstOrDefault();
                                    if (ns != null)
                                    {
                                        curentRange.Worksheet.Cells[i, colcrewid].Value = ns.mans.Trim();
                                        manv = ns.mans.Trim();
                                        curentRange.Worksheet.Cells[i, colnote].Value = "KPT không có CrewID";
                                    }
                                    else
                                    {
                                        curentRange.Worksheet.Cells[i, colnote].Value = "KPT không có CrewID";
                                    }
                                }
                                else //Có khoảng trắng thứ hai ==> Có phần họ và tên đệm
                                {
                                    string sotrung;
                                    sotrung = tentv.Substring(first_space + 1, second_space - first_space - 1);
                                    //Kiểm tra xem phải số trùng tên không
                                    if (Int32.TryParse(sotrung, out tt_ten))
                                    {
                                        hoten = tentv.Substring(second_space + 1).Trim() + " " + tentv.Substring(0, second_space);
                                    }
                                    else
                                    {
                                        hoten = tentv.Substring(first_space + 1).Trim() + " " + tentv.Substring(0, first_space);
                                    }
                                    var ns = hr.HoSoGocs.Where(x => x.tenkodau.Trim().ToUpper() == hoten.ToUpper()).FirstOrDefault();
                                    if (ns != null)
                                    {
                                        curentRange.Worksheet.Cells[i, colcrewid].Value = ns.mans.Trim();
                                        manv = ns.mans.Trim();
                                        curentRange.Worksheet.Cells[i, colnote].Value = "KPT không có CrewID";
                                    }
                                    else
                                    {
                                        curentRange.Worksheet.Cells[i, colnote].Value = "Không tìm được CrewID";
                                    }
                                }
                            }
                            // Nhập mỗi tên không có số trùng tên
                            else
                            {
                                curentRange.Worksheet.Cells[i, colnote].Value = "Không thể tìm được Crew ID";
                            }
                        }
                        #endregion
                        #region Tìm Chuyến Bay
                        if (curentRange.Worksheet.Cells[i, colfltdate].Value.IsDateTime)
                        {
                            ;
                        }
                        flydate = Convert.ToDateTime(curentRange.Worksheet.Cells[i, colfltdate].Value.ToString());
                        route   = curentRange.Worksheet.Cells[i, colroute].Value.ToString();
                        flyno   = "VN" + curentRange.Worksheet.Cells[i, colfltno].Value.ToString();

                        var flight = cb.CR_FlightInfo.Where(x => x.Routing == route && x.FlightNo == flyno && x.Date == flydate.Date).FirstOrDefault();
                        if (flight != null)
                        {
                            curentRange.Worksheet.Cells[i, colflightid].Value = flight.FlightID;
                            id_cb = flight.FlightID;
                            var fltid = lstflightID.Where(x => x == id_cb).FirstOrDefault();
                            if (fltid > 0)
                            {
                                flag_add = true;
                            }
                        }
                        //Tìm DS và S
                        var totv = cb.CR_Flight_Crew.Where(x => x.FlightID == id_cb && x.IsDeleted == false && x.Dutyfree != null && x.Dutyfree != "").OrderBy(z => z.Dutyfree).ToList();
                        if (totv != null)
                        {
                            int k = 0;
                            foreach (var tv in totv)
                            {
                                var hs = hr.HoSoGocs.Where(x => x.mans.Trim() == tv.CrewID).FirstOrDefault();
                                if (hs.mans.Trim() == manv)
                                {
                                    curentRange.Worksheet.Cells[i, colcrewid].Font.Color = System.Drawing.Color.Cyan;
                                }
                                if (hs != null)
                                {
                                    nametv = hs.tenkodau.Trim().ToUpper();
                                }
                                curentRange.Worksheet.Cells[i, colds + k].Value     = tv.CrewID;
                                curentRange.Worksheet.Cells[i, colds + k + 1].Value = nametv;
                                curentRange.Worksheet.Cells[i, colds + k + 2].Value = tv.Dutyfree;
                                k = k + 3;
                                //if(tv.Dutyfree=="S"){
                                //     curentRange.Worksheet.Cells[i,cols].Value=tv.CrewID;
                                //     curentRange.Worksheet.Cells[i,cols+1].Value=nametv;
                                //}
                                //else
                                //    if(tv.Dutyfree=="DS" || tv.Dutyfree=="D"){
                                //        curentRange.Worksheet.Cells[i,colds].Value=tv.CrewID;
                                //        curentRange.Worksheet.Cells[i,colds+1].Value=nametv;
                                //    }
                            }
                        }
                        else
                        {
                            curentRange.Worksheet.Cells[i, colnote].Value = "Không tìm được chuyến bay tương ứng";
                            id_cb = -1;
                        }

                        #endregion
                        #region Lấy thông tin khác
                        if (!curentRange.Worksheet.Cells[i, coldiscrepancy].Value.IsEmpty)
                        {
                            Discrepancy = Convert.ToDouble(curentRange.Worksheet.Cells[i, coldiscrepancy].Value.ToString());
                        }
                        else
                        {
                            Discrepancy = 0.0;
                        }
                        if (!curentRange.Worksheet.Cells[i, colrevenue].Value.IsEmpty)
                        {
                            KPTRevenue = Convert.ToDouble(curentRange.Worksheet.Cells[i, colrevenue].Value.ToString());
                        }
                        else
                        {
                            KPTRevenue = 0.0;
                        }
                        if (!curentRange.Worksheet.Cells[i, colcashier].Value.IsEmpty)
                        {
                            CashierCollected = Convert.ToDouble(curentRange.Worksheet.Cells[i, colcashier].Value.ToString());
                        }
                        else
                        {
                            CashierCollected = 0.0;
                        }
                        if (!curentRange.Worksheet.Cells[i, colcard].Value.IsEmpty)
                        {
                            CardSettlement = Convert.ToDouble(curentRange.Worksheet.Cells[i, colcard].Value.ToString());
                        }
                        else
                        {
                            CardSettlement = 0.0;
                        }
                        if (curentRange.Worksheet.Cells[i, colremark].Value.IsEmpty)
                        {
                            remark = "";
                        }
                        else
                        {
                            remark = curentRange.Worksheet.Cells[i, colremark].Value.ToString(); // ?? curentRange.Worksheet.Cells[i, colremark].Value.ToString(),"";
                        }
                        #endregion
                        #region Ghi vào CSDL
                        if (id_cb > 0)
                        {
                            var dt = cb.CR_Flight_Dutyfree.Where(x => x.FlightID == id_cb).FirstOrDefault();
                            if (dt != null) // Có rồi ==> Cập nhật Total và KPTinfo
                            {
                                if (!flag_add)
                                {
                                    if (Discrepancy > 0)
                                    {
                                        dt.Total = KPTRevenue;
                                    }
                                    else
                                    {
                                        dt.Total = CashierCollected + CardSettlement;
                                    }
                                }
                                else
                                if (Discrepancy > 0)
                                {
                                    dt.Total = dt.Total + KPTRevenue;
                                }
                                else
                                {
                                    dt.Total = dt.Total + CashierCollected + CardSettlement;
                                }

                                dt.KPTinfo    = "Flyno=" + flyno.Trim() + " Date=" + flydate.Date.ToString("dd/MM/yyyy") + " Route=" + route + " Discrepancy=" + Discrepancy.ToString() + " KPT Revenue=" + KPTRevenue.ToString() + " Cashier Collected=" + CashierCollected.ToString() + " Card Settlement " + CardSettlement.ToString() + " Crewid=" + manv + " Crewname=" + tentv + " Remark=" + remark;
                                dt.Modified   = DateTime.Now;
                                dt.Modifier   = "liembt";
                                dt.Modifierid = "1067";
                                cb.SaveChanges();
                                //curentRange.Worksheet.Cells[i, colnote + 1].Value = "Update";
                            }
                            else //Chưa có ==> Add vào
                            {
                                CR_Flight_Dutyfree newdt = new CR_Flight_Dutyfree();

                                newdt.FlightID = id_cb;

                                if (Discrepancy > 0)
                                {
                                    newdt.Total = KPTRevenue;
                                }
                                else
                                {
                                    newdt.Total = CashierCollected + CardSettlement;
                                }

                                newdt.KPTinfo   = "Flyno=" + flyno.Trim() + " Date=" + flydate.Date.ToString("dd/MM/yyyy") + " Route=" + route + " Discrepancy=" + Discrepancy.ToString() + " KPT Revenue=" + KPTRevenue.ToString() + " Cashier Collected=" + CashierCollected.ToString() + " Card Settlement " + CardSettlement.ToString() + " Crewid=" + manv + " Crewname=" + tentv + " Remark=" + remark;
                                newdt.Created   = DateTime.Now;
                                newdt.Creator   = "liembt";
                                newdt.Creatorid = "1067";

                                cb.CR_Flight_Dutyfree.Add(newdt);

                                cb.SaveChanges();
                                //curentRange.Worksheet.Cells[i, colnote + 1].Value = "Insert";
                            }
                        }
                        else
                        {
                            curentRange.Worksheet.Cells[i, colnote + 1].Value = "";
                        }

                        #endregion
                    }
                    #region Export Excel Kết quả xử lý
                    string filename;
                    filename = lblFilename.Text.Substring(0, lblFilename.Text.IndexOf(".")) + "_kqxl.xlsx";
                    IWorkbook workbook = spreadsheetControl1.Document;
                    using (FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite))
                    {
                        workbook.SaveDocument(stream, DocumentFormat.Xlsx);
                    }
                    #endregion
                }
                //catch(Exception ex){
                //    //MessageBox.Show(ex.Message);
                //}
                finally{
                    hr.Dispose();
                    cb.Dispose();
                }
            }
            else
            {
                MessageBox.Show("Vui lòng chọn vùng dữ liệu");
            }

            MessageBox.Show("Complete!");
        }
Exemplo n.º 17
0
 public static bool IsAddItemRange(Cell cell, Range orderItemsRange)
 {
     return(IsSingleCellSelected(cell) &&
            cell.TopRowIndex == orderItemsRange.BottomRowIndex + 1 &&
            cell.LeftColumnIndex - orderItemsRange.LeftColumnIndex == 1);
 }
Exemplo n.º 18
0
        private void btncal_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Worksheet worksheet = spreadsheetControl1.Document.Worksheets.ActiveWorksheet;
            //'预测的对象类型
            // Create sorting fields.
            List <SortField> fields = new List <SortField>();

            // First sorting field. First column (offset = 0) will be sorted using ascending order.
            SortField sortField1 = new SortField();

            sortField1.ColumnOffset = 0;
            sortField1.Comparer     = worksheet.Comparers.Ascending;
            fields.Add(sortField1);

            // Second sorting field. Second column (offset = 1) will be sorted using ascending order.
            SortField sortField2 = new SortField();

            sortField2.ColumnOffset = 1;
            sortField2.Comparer     = worksheet.Comparers.Ascending;
            fields.Add(sortField2);

            // Sort the range by sorting fields.
            // A rectangular range whose left column index is 0, top row index is 0,
            // right column index is 3 and bottom row index is 2. This is the A1:D3 cell range.
            int [] datanum = new int[2];
            datacount(datanum);
            DevExpress.Spreadsheet.Range range = worksheet.Range.FromLTRB(0, 1, datanum[1], datanum[0]);
            worksheet.Sort(range, fields);

            double fluid_type;
            int    math_predic_num = int.Parse(predic_num.Text);

            //List<double> result = new List<double>();
            parameter_result = new List <double>();
            getDatasource    = new List <double[]>();
            wellname         = new List <string>();
            DataTimesource   = new List <DateTime>();
            List <double[]> resultlist = new List <double[]>();
            int             countcol   = importdata(getDatasource, DataTimesource, wellname);

            List <string> listwellname;

            ;
            listwellname = wellname.Distinct().ToList();

            if (getDatasource.Count == 0)
            {
                return;
            }
            for (int k = 0; k < listwellname.Count; k++)
            {
                List <double[]> perwelldata     = new List <double[]>();
                List <DateTime> perwelldatetime = new List <DateTime>();
                for (int i = 0; i < getDatasource.Count; i++)
                {
                    if (wellname[i] == listwellname[k])
                    {
                        perwelldata.Add(getDatasource[i]);
                        perwelldatetime.Add(DataTimesource[i]);
                    }
                }
                int inputnum = getDatasource.Count;


                fluid_type = 0;
                predict_np_time_method(perwelldata, math_predic_num, countcol, resultlist, fluid_type);
            }

            DateTime        lastone    = DataTimesource[DataTimesource.Count - 1];
            List <DateTime> resultTime = new List <DateTime>();

            for (int i = 1; i <= int.Parse(predic_num.Text); i++)
            {
                if (DataTimesource[1].Year - DataTimesource[0].Year == 0)
                {
                    int span = DataTimesource[1].Month - DataTimesource[0].Month;
                    resultTime.Add(lastone.AddMonths(i * span));
                }
                else
                {
                    int span = DataTimesource[1].Year - DataTimesource[0].Year;
                    resultTime.Add(lastone.AddYears(i * span));
                }
            }

            for (int k = 0; k < listwellname.Count; k++)
            {
                for (int i = 0; i < math_predic_num; i++)
                {
                    worksheet.Cells[wellname.Count + math_predic_num * k + 1 + i, 0].Value = listwellname[k];
                    worksheet.Cells[wellname.Count + math_predic_num * k + 1 + i, 1].Value = resultTime[i];
                    for (int j = 0; j < countcol; j++)
                    {
                        worksheet.Cells[wellname.Count + math_predic_num * k + 1 + i, 2 + j].Value = resultlist[j + countcol * k][i];
                    }
                }
            }
            range = worksheet.Range.FromLTRB(0, 1, datanum[1], datanum[0] + math_predic_num * listwellname.Count);
            worksheet.Sort(range, fields);
        }
 public static void CopyOrderItemRange(DevExpress.Spreadsheet.Range itemRange)
 {
     DevExpress.Spreadsheet.Range range = itemRange.Offset(-1, 0);
     range.CopyFrom(itemRange, PasteSpecial.All, true);
 }