void InsertFile(string path, string billNo) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; try { DirectoryInfo mydir = new DirectoryInfo(path); if (!mydir.Exists) { return; } FileInfo[] fileList = mydir.GetFiles(); foreach (FileInfo file in fileList) { string filePath = file.FullName; Guid guid = Guid.NewGuid(); string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1, filePath.LastIndexOf(".") - (filePath.LastIndexOf("\\") + 1)); string fileType = filePath.Substring(filePath.LastIndexOf(".")); string strFtpServerPath = "/" + ServerTime.Time.Year.ToString() + "/" + ServerTime.Time.Month.ToString() + "/"; m_serverFTP.Upload(filePath, strFtpServerPath + guid); if (GetError()) { FM_FilePath lnqTemp = new FM_FilePath(); lnqTemp.FileUnique = guid; lnqTemp.FileType = fileType.ToLower(); lnqTemp.FilePath = strFtpServerPath + guid; lnqTemp.OperationDate = ServerTime.Time; ctx.FM_FilePath.InsertOnSubmit(lnqTemp); ctx.SubmitChanges(); ZL_Database_FileStruct tempLnq = new ZL_Database_FileStruct(); tempLnq.BillNo = billNo; tempLnq.CreationTime = ServerTime.Time; tempLnq.FileUnique = guid; tempLnq.FileName = fileName; tempLnq.ID = Guid.NewGuid(); tempLnq.LastModifyTime = ServerTime.Time; tempLnq.ParentID = null; InsertFileStruct(tempLnq); } } } catch (Exception ex) { throw new Exception(ex.Message); } }
//复制文件,主要是获得要复制的文件的完整路径,具体的复制操作将在粘贴时完成 private void copydirorfile_Click(object sender, EventArgs e) { m_oldFileStruct = m_serverQylityDatabase.GetFileStructInfo(this.listView1.SelectedItems[0].SubItems[5].Text.Trim()); m_oldListViewItem = this.listView1.SelectedItems[0]; paste.Enabled = true; }
//创建文件 private void createnewfile_Click(object sender, EventArgs e) { try { if (openFileDialog1.ShowDialog() == DialogResult.OK) { Guid guid = Guid.NewGuid(); string fileName = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf("\\") + 1, openFileDialog1.FileName.LastIndexOf(".") - (openFileDialog1.FileName.LastIndexOf("\\") + 1)); string fileType = openFileDialog1.FileName.Substring(openFileDialog1.FileName.LastIndexOf(".")); string strFtpServerPath = "/" + ServerTime.Time.Year.ToString() + "/" + ServerTime.Time.Month.ToString() + "/"; CursorControl.SetWaitCursor(this); m_serverFTP.Upload(openFileDialog1.FileName, strFtpServerPath + guid); this.Cursor = System.Windows.Forms.Cursors.Arrow; if (GetError()) { m_serverFileBasic.AddFile(guid, strFtpServerPath + guid, fileType); this.listView1.LabelEdit = true; ZL_Database_FileStruct tempLnq = new ZL_Database_FileStruct(); tempLnq.BillNo = txtBillNo.Text; tempLnq.CreationTime = ServerTime.Time; tempLnq.FileUnique = guid; tempLnq.FileName = fileName; tempLnq.ID = Guid.NewGuid(); tempLnq.LastModifyTime = ServerTime.Time; tempLnq.ParentID = currentParentID == "" ? null : (Guid?)(new Guid(currentParentID)); m_serverQylityDatabase.InsertFileStruct(tempLnq); ListViewItem item = new ListViewItem(new String[] { tempLnq.FileName, m_serverFTP.GetFileSize(strFtpServerPath + guid).ToString(), fileType, tempLnq.CreationTime.ToString(), tempLnq.LastModifyTime.ToString(), tempLnq.ID.ToString(), strFtpServerPath + guid, tempLnq.ParentID.ToString() }, 0); SetListViewItemExtention(fileType, ref item); this.listView1.Items.Add(item); this.listView1.Items[this.listView1.Items.Count - 1].BeginEdit(); } } } catch (Exception ex) { MessageDialog.ShowErrorMessage(ex.Message); this.Cursor = System.Windows.Forms.Cursors.Arrow; } }
/// <summary> /// 插入一条文件信息 /// </summary> /// <param name="fileStruct">文件信息数据集</param> public void InsertFileStruct(ZL_Database_FileStruct fileStruct) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; var varData = from a in ctx.ZL_Database_FileStruct where a.ID == fileStruct.ID select a; if (varData != null && varData.Count() == 0) { ctx.ZL_Database_FileStruct.InsertOnSubmit(fileStruct); ctx.SubmitChanges(); } }
private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e) { if (e.Label == null) { return; } else { ZL_Database_FileStruct tempFileStruct = m_serverQylityDatabase.GetFileStructInfo(this.listView1.SelectedItems[0].SubItems[5].Text.Trim()); tempFileStruct.FileName = e.Label; if (this.listView1.SelectedItems[0].SubItems[2].Text.Trim().Equals("文件夹")) { foreach (ListViewItem item in listView1.Items) { if (item.SubItems[2].Text.Trim().Equals("文件夹") && item.SubItems[5].Text.Trim() != tempFileStruct.ID.ToString() && item.SubItems[0].Text.Trim() == tempFileStruct.FileName) { MessageBox.Show("无法从命名文件夹" + e.Label + " " + "制定文件夹与现有文件夹同名,请另外指定文件夹名", "文件夹重命名错误", MessageBoxButtons.OK, MessageBoxIcon.Error); e.CancelEdit = true; return; } } } else { foreach (ListViewItem item in listView1.Items) { if (!item.SubItems[2].Text.Trim().Equals("文件夹") && item.SubItems[5].Text.Trim() != tempFileStruct.ID.ToString() && item.SubItems[0].Text.Trim() == tempFileStruct.FileName) { MessageBox.Show("无法从命名文件" + e.Label + " " + "制定文件与现有文件同名,请另外指定文件名", "文件重命名错误", MessageBoxButtons.OK, MessageBoxIcon.Error); e.CancelEdit = true; return; } } } m_serverQylityDatabase.UpdateFileStruct(tempFileStruct); } }
/// <summary> /// 编辑文件结构信息 /// </summary> /// <param name="fileStruct">LNQ文件结构信息集合</param> public void EditFileStruct(ZL_Database_FileStruct fileStruct) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; try { if (fileStruct == null) { throw new Exception("录入数据信息为空"); } var varData = from a in ctx.ZL_Database_FileStruct where a.ID == fileStruct.ID select a; if (varData == null || varData.Count() == 0) { fileStruct.CreationTime = ServerTime.Time; ctx.ZL_Database_FileStruct.InsertOnSubmit(fileStruct); } else if (varData.Count() == 1) { ZL_Database_FileStruct tempLnq = varData.Single(); tempLnq.BillNo = fileStruct.BillNo; tempLnq.FileName = fileStruct.FileName; tempLnq.FileUnique = fileStruct.FileUnique; tempLnq.LastModifyTime = ServerTime.Time; tempLnq.ParentID = fileStruct.ParentID; } else { throw new Exception("文件结构信息数据不唯一"); } } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// 更新一条文件信息 /// </summary> /// <param name="fileStruct">文件信息数据集</param> public void UpdateFileStruct(ZL_Database_FileStruct fileStruct) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; var varData = from a in ctx.ZL_Database_FileStruct where a.ID == fileStruct.ID select a; if (varData != null && varData.Count() == 1) { ZL_Database_FileStruct tempLnq = varData.Single(); tempLnq.BillNo = fileStruct.BillNo; tempLnq.FileName = fileStruct.FileName; tempLnq.FileUnique = fileStruct.FileUnique; tempLnq.LastModifyTime = fileStruct.LastModifyTime; tempLnq.ParentID = fileStruct.ParentID; ctx.SubmitChanges(); } }
//创建文件夹 private void createnewdir_Click(object sender, EventArgs e) { this.listView1.LabelEdit = true; ZL_Database_FileStruct tempLnq = new ZL_Database_FileStruct(); tempLnq.BillNo = txtBillNo.Text; tempLnq.CreationTime = ServerTime.Time; tempLnq.FileName = "新建文件夹"; tempLnq.ID = Guid.NewGuid(); tempLnq.LastModifyTime = ServerTime.Time; tempLnq.ParentID = currentParentID == "" ? null : (Guid?)(new Guid(currentParentID)); m_serverQylityDatabase.InsertFileStruct(tempLnq); ListViewItem item = new ListViewItem(new String[] { tempLnq.FileName, "", "文件夹", tempLnq.CreationTime.ToString(), tempLnq.LastModifyTime.ToString(), tempLnq.ID.ToString(), "", tempLnq.ParentID.ToString() }, 0); this.listView1.Items.Add(item); this.listView1.Items[this.listView1.Items.Count - 1].BeginEdit(); }