private FileDataSet ReadDataFile(SQLInboundChanel ch, FileDataSet fds) { if (fds == null) { return(null); } if (SQLInAdapterConfigMgt.SQLInAdapterConfig.ThirdPartyInteractConfig.ConnectionParameter.FileTransformBeforeRead) { Program.Log.Write("Transforming file: " + fds.DataFileName); string filelocation = Path.Combine(SQLInAdapterConfigMgt.SQLInAdapterConfig.ThirdPartyInteractConfig.ConnectionParameter.FileFolder, fds.DataFileName); string filecontent = File.ReadAllText(filelocation); filecontent = SQLInAdapterConfigMgt.SQLInAdapterConfig.ThirdPartyInteractConfig.ConnectionParameter.FileTransformRule.Replace(filecontent, Program.Log); File.WriteAllText(filelocation, filecontent); } OleDbCommand cmd = Program.db.GetCommand(); cmd.CommandText = ch.Rule.QueryCriteria.SQLStatement .Replace("{FileName}", string.Format("[{0}]", fds.DataFileName)); cmd.CommandType = CommandType.Text; Program.Log.Write("CommandText='" + cmd.CommandText + "'"); DataSet ds = new DataSet(); if (!Program.db.ExecCommand(cmd, ds)) { return(null); } fds.DataSet = ds; return(fds); }
private void btnDownload_Click(object sender, EventArgs e) { try { FileDataSet dataset = this.fileDataSet; dataset = this.fileDataSet; // fileType = "档案"; int[] selIndexs = gridView2.GetSelectedRows(); foreach (int i in selIndexs) { DataRowView rv = gridView2.GetRow(i) as DataRowView; if (rv != null) { string fileID = rv["FILEID"].ToString(); saveFileDialog.DefaultExt = "图片文件 (*.jpg)|*.jpg,*.jpeg"; if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fileName = saveFileDialog.FileName; byte[] bfile = dataset.GetImageByID(fileID); File.WriteAllBytes(fileName, bfile); } } } } catch (Exception ex) { UserMessages.ShowInfoBox(ex.Message); } }
public override global::System.Data.DataSet Clone() { FileDataSet cln = ((FileDataSet)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
private void HandleDataFile(FileDataSet fds, bool success) { bool hasIndex = !string.IsNullOrEmpty(fds.IndexFileLocation); if (success) { if (hasIndex) { Program.Log.Write("Deleting success file: " + fds.IndexFileLocation); File.Delete(fds.IndexFileLocation); } Program.Log.Write("Deleting success file: " + fds.DataFileLocation); File.Delete(fds.DataFileLocation); } else { ThirdDBConnection config = SQLInAdapterConfigMgt.SQLInAdapterConfig.ThirdPartyInteractConfig.ConnectionParameter; if (config.MoveFileWhenError) { string mFolder = ConfigHelper.GetFullPath(config.MoveFileFolder); if (!Directory.Exists(mFolder)) { Directory.CreateDirectory(mFolder); } if (hasIndex) { string mIFolder = Path.Combine(mFolder, "Index"); if (!Directory.Exists(mIFolder)) { Directory.CreateDirectory(mIFolder); } string iFileName = Path.GetFileName(fds.IndexFileLocation); string iFile = Path.Combine(mIFolder, iFileName); Program.Log.Write("Moving error index file to: " + iFile); File.Move(fds.IndexFileLocation, iFile); } string mDFolder = Path.Combine(mFolder, "Data"); if (!Directory.Exists(mDFolder)) { Directory.CreateDirectory(mDFolder); } string dFile = Path.Combine(mDFolder, fds.DataFileName); Program.Log.Write("Moving error data file to: " + dFile); File.Move(fds.DataFileLocation, dFile); } else { if (hasIndex) { Program.Log.Write("Deleting error file: " + fds.IndexFileLocation); File.Delete(fds.IndexFileLocation); } Program.Log.Write("Deleting error file: " + fds.DataFileLocation); File.Delete(fds.DataFileLocation); } } }
private List <FileDataSet> FindDataFiles() { List <FileDataSet> list = new List <FileDataSet>(); ThirdDBConnection config = SQLInAdapterConfigMgt.SQLInAdapterConfig.ThirdPartyInteractConfig.ConnectionParameter; if (config.IndexFileDriven) { string iFolder = ConfigHelper.GetFullPath(config.IndexFileFolder); string[] iflist = Directory.GetFiles(iFolder, config.FileNamePattern); Program.Log.Write(string.Format("Find {0} index file in folder {1}", iflist.Length, iFolder)); foreach (string f in iflist) { string iFile = ConfigHelper.GetFullPath(iFolder, f); string iFileName = Path.GetFileNameWithoutExtension(iFile); string dFileNamePattern = string.Format("{0}.*", iFileName); string dFolder = ConfigHelper.GetFullPath(config.FileFolder); string[] dflist = Directory.GetFiles(dFolder, dFileNamePattern); if (dflist.Length < 1) { Program.Log.Write(LogType.Error, string.Format("Cannot find data file with pattern {0} in folder {1}", dFileNamePattern, dFolder)); continue; } string dFile = ConfigHelper.GetFullPath(dFolder, dflist[0]); FileDataSet fds = new FileDataSet(); fds.IndexFileLocation = iFile; fds.DataFileLocation = dFile; fds.DataFileName = Path.GetFileName(dFile); Program.Log.Write(string.Format("Find data file named {0} from {1} with index file {2}", fds.DataFileName, fds.DataFileLocation, fds.IndexFileLocation)); list.Add(fds); } } else { string dFolder = ConfigHelper.GetFullPath(config.FileFolder); string[] dflist = Directory.GetFiles(dFolder, config.FileNamePattern); Program.Log.Write(string.Format("Find {0} data file in folder {1}", dflist.Length, dFolder)); foreach (string f in dflist) { string dFile = ConfigHelper.GetFullPath(dFolder, f); FileDataSet fds = new FileDataSet(); fds.DataFileLocation = dFile; fds.DataFileName = Path.GetFileName(dFile); Program.Log.Write(string.Format("Find data file named {0} from {1}", fds.DataFileName, fds.DataFileLocation)); list.Add(fds); } } return(list); }
private void btnUpload_Click(object sender, EventArgs e) { try { FileDataSet dataset = this.fileDataSet; string fileType = "档案"; if (tabbedControlGroup1.SelectedTabPageIndex == 1) { fileType = "合同"; dataset = this.HTfileDataSet; } else { dataset = this.fileDataSet; fileType = "档案"; } DataRowView rv = tW_ClientBindingSource.Current as DataRowView; if (rv == null) { return; } string fkID = rv["客户名称ID"].ToString(); openFileDialog.DefaultExt = "图片文件 (*.jpg)|*.jpg;*.jpeg;*.png"; openFileDialog.Filter = "图片文件 (*.jpg)|*.jpg;*.jpeg;*.png"; openFileDialog.Multiselect = true; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string[] fileNames = openFileDialog.FileNames; splash.ShowWaitForm(); foreach (string fileName in fileNames) { this.splash.SetWaitFormCaption("上传文件"); this.splash.SetWaitFormDescription("正在上传文件…"); FileStream fileStream = new FileStream(fileName, FileMode.Open); fileStream.Seek(0, SeekOrigin.Begin); Byte[] fileByte = new Byte[(int)fileStream.Length]; //转换字节流 fileStream.Read(fileByte, 0, fileByte.Length); dataset.AddImage(fileByte, fileName, fileType, fkID); dataset.SaveImage(); } } } catch (Exception ex) { UserMessages.ShowInfoBox(ex.Message); } finally { if (splash.IsSplashFormVisible) { splash.CloseWaitForm(); } } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { FileDataSet ds = new FileDataSet(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
private void btnDownload_Click(object sender, EventArgs e) { try { DevExpress.XtraGrid.Views.Grid.GridView aGrid = null; FileDataSet dataset = this.fileDataSet; // string fileType = "档案"; int[] selIndexs; if (tabbedControlGroup1.SelectedTabPageIndex == 1) { // fileType = "合同"; dataset = this.HTfileDataSet; selIndexs = gridView3.GetSelectedRows(); aGrid = gridView3; } else { dataset = this.fileDataSet; // fileType = "档案"; selIndexs = gridView2.GetSelectedRows(); aGrid = gridView2; } foreach (int i in selIndexs) { DataRowView rv = aGrid.GetRow(i) as DataRowView; if (rv != null) { string fileID = rv["FILEID"].ToString(); saveFileDialog.DefaultExt = "图片文件 (*.jpg)|*.jpg,*.jpeg"; if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fileName = saveFileDialog.FileName; byte[] bfile = dataset.GetImageByID(fileID); File.WriteAllBytes(fileName, bfile); } } } } catch (Exception ex) { UserMessages.ShowInfoBox(ex.Message); } }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); FileDataSet ds = new FileDataSet(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "TF_FILEDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
private void btnUpload_Click(object sender, EventArgs e) { try { FileDataSet dataset = this.fileDataSet; string fileType = "档案"; DataRowView rv = tW_BusinessRegBindingSource.Current as DataRowView; if (rv == null) { return; } bool wqSP = false; if (!string.IsNullOrEmpty(rv["外勤审批确认"].ToString())) { wqSP = bool.Parse(rv["外勤审批确认"].ToString()); } if (wqSP) { UserMessages.ShowInfoBox("审批完成不能修改文件!"); return; } string clientName = rv["公司预核名称"].ToString(); string fkID = businessDataSet.GetClientId(clientName); if (string.IsNullOrEmpty(fkID)) { UserMessages.ShowInfoBox("公司名称不存在客户信息中!"); return; } openFileDialog.DefaultExt = "图片文件 (*.jpg)|*.jpg;*.jpeg;*.png"; openFileDialog.Filter = "图片文件 (*.jpg)|*.jpg;*.jpeg;*.png"; openFileDialog.Multiselect = true; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string[] fileNames = openFileDialog.FileNames; splash.ShowWaitForm(); foreach (string fileName in fileNames) { this.splash.SetWaitFormCaption("上传文件"); this.splash.SetWaitFormDescription("正在上传文件…"); FileStream fileStream = new FileStream(fileName, FileMode.Open); fileStream.Seek(0, SeekOrigin.Begin); Byte[] fileByte = new Byte[(int)fileStream.Length]; //转换字节流 fileStream.Read(fileByte, 0, fileByte.Length); dataset.AddImage(fileByte, fileName, fileType, fkID); dataset.SaveImage(); } } } catch (Exception ex) { UserMessages.ShowInfoBox(ex.Message); } finally { if (splash.IsSplashFormVisible) { splash.CloseWaitForm(); } } }
private void QueryDataFile() { foreach (SQLInboundChanel ch in SQLInAdapterConfigMgt.SQLInAdapterConfig.InboundChanels) { try { if (!ch.Enable) { continue; } if (ch.OperationType != ThrPartyDBOperationType.Table) { continue; } Program.Log.Write("Begin processing channel: " + ch.ChannelName); List <FileDataSet> flist = FindDataFiles(); if (flist.Count > 0) { foreach (FileDataSet f in flist) { FileDataSet fds = ReadDataFile(ch, f); if (fds == null) { Program.Log.Write(LogType.Error, "Read data failed.\r\n" + Program.db.LastError); continue; } DataSet ds1 = fds.DataSet; DataSet ds2 = TranslateData(ch, ds1); Program.db.CloseDBConnection(); if (ds2 == null) { Program.Log.Write(LogType.Error, "Process data failed."); continue; } Program.Log.Write("Receive record count: " + ds2.Tables[0].Rows.Count.ToString()); bool res = false; if (OnDataReceived != null) { Program.Log.Write("before OnDataReceived(ch.Rule, ds2);"); res = OnDataReceived(ch.Rule, ds2); Program.Log.Write("after OnDataReceived(ch.Rule, ds2); result: " + res.ToString()); } else { Program.Log.Write(LogType.Error, "OnDataReceived = null"); } HandleDataFile(fds, res); } } Program.Log.Write("End processing channel: " + ch.ChannelName); } catch (Exception err) { Program.Log.Write(err); } } }
private void OnImportButtonClick(object sender, EventArgs e) { using (OpenFileDialog dialog = new OpenFileDialog()) { const string ext = ".fvis-values"; dialog.CheckFileExists = true; dialog.Filter = Tx.T("dataset.filetype") + " (*" + ext + ")|*" + ext; dialog.FilterIndex = 0; dialog.RestoreDirectory = true; dialog.Title = Tx.T("dataset.load"); if (dialog.ShowDialog(this) != DialogResult.OK) { return; } string filename = dialog.FileName; using (FileStream s = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) using (BinaryReader br = new BinaryReader(s)) { byte[] header = br.ReadBytes(4); if (header[0] != 'f' || header[1] != 'V' || header[2] != 'i' || header[3] != 's') { MessageBox.Show(this, Tx.T("dataset.errors.file not valid"), Tx.T("main.error"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int flags = br.ReadInt32(); string description = br.ReadString(); long axisX = br.ReadInt64(); long axisY = br.ReadInt64(); double scaleFactor = br.ReadDouble(); ulong count = br.ReadUInt64(); if (count <= 0) { MessageBox.Show(this, Tx.T("dataset.errors.file not valid"), Tx.T("main.error"), MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ulong offset = (ulong)s.Position; // Close stream and open the same file in memory-mapped mode s.Close(); FileDataSet fileDataSet = new FileDataSet(filename, offset, count); // Add item to ListView StringBuilder sb = new StringBuilder(); sb.Append("\f[I]\f[0x888888]" + Tx.T("dataset.part of function") + " \f[Rc]\f[I]"); int i = description.IndexOf('#'); if (i != -1) { while (i > 0 && description[i - 1] == ' ') { i--; } sb.Append(description, 0, i); sb.Append("\f[0x498E3E]"); sb.Append(description, i, description.Length - i); } else { sb.Append(description); } ListView.Item item = new ListView.Item { NumericValueSource = fileDataSet, Text = description, TextDisplay = sb.ToString(), Color = FindNewColor(), CheckState = CheckState.Checked, CheckEnabled = true, ImageResourceCallback = OnImageResourceCallback }; listView.Items.Add(item); listView.FocusedItem = item; listView.Invalidate(); listView.Update(); listView.EnsureVisible(item); // Zoom to values in graph graph.ScaleFactor = scaleFactor; graph.AxisX = axisX; graph.AxisY = axisY; } } }
private void UpdateFileProperties(FileDataSet.FilePropertiesRow row) { FileInfo fileInfo = new FileInfo(row.Name); if (row.SummaryPropsFlag) { OleDocumentProperties props = null; try { props = new OleDocumentProperties(); props.Open(fileInfo.FullName, false, dsoFileOpenOptions.dsoOptionDefault); SummaryProperties summaryProps = props.SummaryProperties; summaryProps.Author = row.SummaryPropsAuthor; summaryProps.Category = row.SummaryPropsCategory; summaryProps.Comments = row.SummaryPropsComments; summaryProps.Company = row.SummaryPropsCompany; summaryProps.Keywords = row.SummaryPropsKeywords; summaryProps.LastSavedBy = row.SummaryPropsLastSavedBy; summaryProps.Manager = row.SummaryPropsManager; //summaryProps.RevisionNumber = row.SummaryPropsRevisionNumber; summaryProps.Subject = row.SummaryPropsSubject; //summaryProps.Template = row.SummaryPropsTemplate; summaryProps.Title = row.SummaryPropsTitle; //summaryProps.Version = row.SummaryPropsVersion; props.Save(); } catch (Exception e) { Utils.ShowErrorMessage("プロパティの変更に失敗しました。\r\n" + "ファイル=" + row.Name + "\r\n" + "エラー詳細=" + e.Message); return; } finally { if (props != null) { props.Close(false); } } } // 変更を確定する row.AcceptChanges(); }
private void AddFilePropertiesRow(FileDataSet.FilePropertiesRow row) { if (InvokeRequired) { Invoke(new AddFilePropertiesRowDelegate(AddFilePropertiesRow), new object[]{ row }); return; } fileDataSet.FileProperties.Rows.Add(row); }