Example #1
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");
            }
        }
Example #2
0
 protected override void Dispose(bool disposing)
 {
     _context.Dispose();
 }