public FileResult Export(string beginTime1, string endTime1, string searchkey, string slaveid) { DateTime dt = DateTime.Now; if (string.IsNullOrEmpty(beginTime1) && string.IsNullOrEmpty(endTime1)) { beginTime1 = dt.ToString("yyyy/MM/01 00:00"); endTime1 = dt.ToString("yyyy/MM/dd 23:59"); } if (string.IsNullOrEmpty(slaveid)) { slaveid = "0"; } byte[] bytes = new byte[1]; List <WaterMeterParas> list = GetAllAttendanceInfos(beginTime1, endTime1, searchkey, slaveid); ITransferData transdata = TransferDataFactory.GetUtil(DataFileType.CSV); DataTable dataTable = new WaterSupplyInfoGetter().GetTable(list); MemoryStream stream = transdata.GetStream(dataTable) as MemoryStream; stream.Seek(0, SeekOrigin.Begin); StreamReader sr = new StreamReader(stream, new UTF8Encoding(true)); string strContent = sr.ReadToEnd(); Encoding ecd = new UTF8Encoding(true); bytes = ecd.GetBytes(strContent); byte[] bytesConvent = new byte[bytes.Length + 3]; bytesConvent[0] = 0xEF; bytesConvent[1] = 0xBB; bytesConvent[2] = 0xBF; Array.Copy(bytes, 0, bytesConvent, 3, bytes.Length); return(File(bytesConvent, "application/vnd.ms-excel", Server.UrlEncode(string.Format("用水量信息{0}_{1}.csv", DateTime.Parse(beginTime1).ToString("yyyy-MM-dd-HH-mm-ss"), DateTime.Parse(endTime1).ToString("yyyy-MM-dd-HH-mm-ss"))))); }
/// <summary> /// Initializes a new instance of the <see cref="Xwt.DragOverEventArgs"/> class. /// </summary> /// <param name="position">The potential drop coordinates (in widget coordinates).</param> /// <param name="dataStore">The collection of transferred data.</param> /// <param name="action">The proposed drag&drop action type.</param> public DragOverEventArgs(Point position, ITransferData dataStore, DragDropAction action) { Position = position; Data = dataStore; Action = action; AllowedAction = DragDropAction.Default; }
public DragEventArgs(Point position, ITransferData data, DragDropAction action) { Data = data; Position = position; Action = action; Success = false; }
public DataTable BindGrid() { string fileName = this.selectDialog.Text; DataTable dt = new DataTable(); if (!string.IsNullOrEmpty(fileName)) { string ext = Path.GetExtension(fileName).ToLower(); FileType fileType = FileHelper.GetFileType(ext); bool isFirstColumn = true; string[] columns = new string[] { "联系人", "号码", "号码类型" }; this.grid1.AutoGenerateColumns = true; this.grid1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; this.grid1.ReadOnly = true; this.grid1.DataSource = null; if (fileType == FileType.Txt) { dt = TxtHelper.ParseDataTable(fileName, columns, isFirstColumn); } else if (fileType == FileType.Excel) { ITransferData t = TransferDataFactory.GetTransferData(fileName); dt = t.GetData(fileName, columns, isFirstColumn); } else { dt = TxtHelper.ToDataTable(AddressBook.Parse(fileName), columns, isFirstColumn); } this.grid1.DataSource = dt; } return(dt); }
public DragOverEventArgs(Point position, ITransferData info, DragDropAction action) { Position = position; Info = info; Action = action; AllowedAction = DragDropAction.Default; }
/// <summary> /// 解析通讯录文件 /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static string Parse(string fileName) { if (!string.IsNullOrEmpty(fileName)) { string ext = Path.GetExtension(fileName).ToLower(); StringBuilder sb = new StringBuilder(); try { string text = FileHelper.GetFileContent(fileName, Encoding.UTF8); FileType fileType = FileHelper.GetFileType(ext); if (!string.IsNullOrEmpty(text)) { bool isFirstColumn = false; string[] columns = new string[] { "联系人", "号码", "号码类型" }; string templ = "{0}\t{1}\t{2}"; if (ext == ".vcf") { sb.AppendLine(string.Format(templ, columns[0], columns[1], columns[2])); string regexName = @"^(?:FN:)(.*)(?:/*.*)$"; MatchCollection matchName = Regex.Matches(text, regexName, RegexOptions.IgnoreCase | RegexOptions.Multiline); string regexTel = @"^(?:TEL;TYPE=CELL(?:;TYPE=PREF)?:)((\+86)?\d{11,12})"; MatchCollection matchTel = Regex.Matches(text, regexTel, RegexOptions.IgnoreCase | RegexOptions.Multiline); if (matchName.Count > 0 && matchTel.Count > 0) { for (int i = 0; i < matchName.Count; i++) { string name = Regex.Replace(matchName[i].Groups[1].Value, "/+.*$", ""); string value = matchTel[i].Groups[1].Value; string type = Regex.IsMatch(value, @"^(\+86){1}\d{11}$") ? "联通" : "移动"; string tel = Regex.Replace(value, @"^(\+86){1}", ""); if (tel.StartsWith("0")) { type = "座机"; } sb.AppendLine(string.Format(templ, name, tel, type)); } } } else if (fileType == FileType.Txt) { sb.Append(text); } else if (fileType == FileType.Excel) { ITransferData transfer = TransferDataFactory.GetTransferData(fileName); DataTable dt = transfer.GetData(fileName, columns, isFirstColumn); sb.Append(TxtHelper.ToTextContent(dt)); } } } catch (Exception ex) { sb.Append(ex.Message); } return(sb.ToString()); } return(string.Empty); }
//加载数据 private void btnLoadImport_Click(object sender, EventArgs e) { this.gridImport.AutoGenerateColumns = true; this.gridImport.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; string fileName = this.selectDialogImport.Text; if (!string.IsNullOrWhiteSpace(fileName)) { ITransferData trans = TransferDataFactory.GetTransferData(fileName); DataTable dt = trans.GetData(fileName, null, true); dt.TableName = Path.GetFileNameWithoutExtension(fileName); this.gridImport.DataSource = dt; } }
private void ExportFile(TransferFileType type, DataTable dt = null) { if (dt == null) { dt = this.filterData1.GetDataSource(); } if (dt != null) { string savePath = Dialog.GetSaveFile(TableName + TransferDataFactory.GetFileExtension(type)); if (!string.IsNullOrEmpty(savePath)) { ITransferData transfer = TransferDataFactory.GetTransferData(type); byte[] bytes = transfer.GetBytes(dt, true); FileHelper.WriteFile(savePath, bytes); if (MsgBox.Confirm("导出完毕,是否打开文件?")) { FileHelper.OpenFile(savePath); } } } }
public DragOverEventArgs(Point position, ITransferData dataStore, DragDropAction action) { Position = position; Data = dataStore; Action = action; AllowedAction = DragDropAction.Default; }
/// <summary> /// Encapsulate a <see cref="System.IO.Stream" />. /// </summary> /// <param name="stream">The stream to calculate the checksum for.</param> public InternalCrcStream(ITransferData stream) => Stream = stream;
public virtual IVisual VisualOfTransferData(IGraph <IVisual, IVisualEdge> graph, ITransferData data) { var value = data.GetValue(TransferDataType.FromType(typeof(IVisual))); var bytes = value as byte []; if (bytes != null) { return(TransferDataSource.DeserializeValue(bytes) as IVisual); } #if TRACE var dt = ""; data.DataTypes.ForEach(d => dt += d.Id + " | "); Trace.WriteLine($"{nameof(DragDropViz)}.{nameof (VisualOfTransferData)}\t{dt}"); #endif Stream stream = null; Content <Stream> content = null; string desc = null; string source = null; Func <ContentInfo, Stream, Content <Stream> > fillContent = (i, s) => { bool newContent = content == null || s != content.Data; var content1 = new Content <Stream> (content) { Data = newContent ? s : content.Data, ContentType = newContent ? i.ContentType : content.ContentType, Compression = newContent ? i.Compression : content.Compression, }; content1 = ContentDiggPool.Use(content1); desc = desc ?? content1?.Description?.ToString(); source = source ?? content1?.Source?.ToString(); return(content1); }; if (data.Uris.Length > 0) { //TODO: handle more then one file foreach (var uri in data.Uris.OrderBy(n => n.ToString())) { IContentIo <Stream> sink = null; string uridesc = null; if (uri.IsFile) { var fileName = IoUtils.UriToFileName(uri); if (File.Exists(fileName)) // TODO: check if filename is directory { stream = File.OpenRead(fileName); sink = DataManager.SinkOf(Path.GetExtension(fileName).TrimStart('.').ToLower()); uridesc = Path.GetFileNameWithoutExtension(fileName); } } else if (uri.HostNameType == UriHostNameType.Dns) { try { using (var cli = new WebClient()) { bytes = cli.DownloadData(uri); stream = new MemoryStream(bytes); } uridesc = uri.ToString(); } catch (Exception webEx) { Registry.Pooled <IMessageBoxShow> ().Show("Download failed", $"The uri \n{uri.ToString ()}\ncould not be loaded: {webEx.Message}", MessageBoxButtons.Ok); } } if (stream != null) { ContentInfo info = null; if (sink == null) { sink = DataManager.SinkOf(stream); } if (sink != null) { info = sink.Use(stream); } if (sink == null) { info = new ContentInfo("Unknown", ContentTypes.Unknown, "*", null, CompressionType.neverCompress); } content = fillContent(info, stream); if (content.Description == null) { content.Description = uridesc; } content.Source = uridesc; if (data.Uris.Length > 1) { Registry.Pooled <IMessageBoxShow> ().Show("DragDrop multiple files", string.Format("Only one file {0} will be stored currently", uri.AbsolutePath), MessageBoxButtons.Ok); } break; } } } else { var dataTypes = data.DataTypes.ToArray(); if (data.Text != null) { using (var dr = new StringReader(data.Text)) desc = dr.ReadLine(); } foreach (var s in DataManager.SinksOf(dataTypes).ToArray()) { var transferType = s.Item1; value = data.GetValue(transferType); var sink = s.Item2; stream = value as Stream; bytes = value as byte []; if (bytes != null) { stream = new MemoryStream(bytes); } var text = value as string; if (text != null) { stream = text.AsUnicodeStream(); } if (stream != null) { var info = sink.Use(stream); var contentSpec = sink.Detector; if (info == null && contentSpec != null) { info = contentSpec.FindMime(s.Item1.Id); } if (info == null) { info = DataManager.InfoOf(sink, dataTypes).FirstOrDefault(); } if (info != null && content == null || content.Data == null) { content = fillContent(info, stream); // TODO: find a better handling of preferences; maybe MimeFingerPrints does the job? if (content.Data == null || desc == null || source == null) { continue; } } else if (info != null) { fillContent(info, stream); if (desc == null || source == null) { continue; } } if (content != null) { if (content.Description == null) { content.Description = desc; } if (content.Source == null) { content.Source = source; } } } } } if (content != null) { #if TRACE Trace.WriteLine($"{nameof (VisualOfTransferData)}\tDragged:\t{content.ContentType.MimeType ()}"); #endif var result = VisualContentViz.VisualOfContent(graph, content); if (stream is FileStream) { stream.Close(); } return(result); } return(null); }