private void dgv_Data_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { int rowindex = e.RowIndex; int columnindex = e.ColumnIndex; string id = dgv_Data.Rows[rowindex].Cells["ID"].Value.ToString(); if (columnindex == 0) //编辑 { lb_ID.Text = id; tb_Code.Text = dgv_Data.Rows[rowindex].Cells["Code"].Value.ToString(); tb_Title.Text = dgv_Data.Rows[rowindex].Cells["Title"].Value.ToString(); tb_Remark.Text = dgv_Data.Rows[rowindex].Cells["Remark"].Value.ToString(); cb_Postfix.Text = dgv_Data.Rows[rowindex].Cells["Postfix"].Value.ToString(); IUpLoadFile ufDal = new AccessDal.CodeMaker.UpLoadFile(); UpLoadFileInfo upfInfo = ufDal.UpLoadFileGetInfo("Cm_Templet", int.Parse(id)); if (upfInfo != null) { string fpath = AppDomain.CurrentDomain.BaseDirectory + upfInfo.FilePath + "\\" + upfInfo.UniqueName; string Content = Common.FileHandle.ReadFile(fpath); textEditorControl.Text = Content; } } else if (columnindex == 1) //删除 { if (MessageBox.Show("确认删除?", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes) { IUpLoadFile ufDal = new AccessDal.CodeMaker.UpLoadFile(); UpLoadFileInfo upfInfo = new UpLoadFileInfo(); upfInfo = ufDal.UpLoadFileGetInfo("Cm_Templet", int.Parse(id)); if (upfInfo != null && upfInfo.FileID != 0) { string fpath = AppDomain.CurrentDomain.BaseDirectory + upfInfo.FilePath + "\\" + upfInfo.UniqueName; Common.FileHandle.DeleteFile(fpath); if (ufDal.UpLoadFile_Del(upfInfo.FileID) != 1) { MessageBox.Show("删除失败。"); return; } } if (dal.Templet_Del(int.Parse(id)) == 1) { QueryData(); MessageBox.Show("删除成功。"); } else { MessageBox.Show("删除失败。"); } } } }
/// <summary> /// 保存数据 /// </summary> private void SaveData() { TempletInfo info = new TempletInfo(); info.Code = tb_Code.Text.Trim(); info.Title = tb_Title.Text.Trim(); info.Content = ""; info.Remark = tb_Remark.Text.Trim(); info.Postfix = cb_Postfix.Text; info.Path = ""; string Content = textEditorControl.Text; if (ParentInfo == null && lb_ID.Text == "") { MessageBox.Show("请选择目录。"); return; } if (info.Title == "") { MessageBox.Show("请输入名称。"); return; } if (Content == "") { MessageBox.Show("请输入内容。"); return; } if (info.Postfix == "") { MessageBox.Show("请选择后缀名称。"); return; } int rst = -1; int TempletID = 0; if (lb_ID.Text == "") { info.ParentID = ParentInfo.ID; rst = dal.Templet_Add(info, out TempletID); } else { info.ID = int.Parse(lb_ID.Text); TempletID = info.ID; rst = dal.Templet_Edit(info); } if (rst == 1) { IUpLoadFile ufDal = new AccessDal.CodeMaker.UpLoadFile(); UpLoadFileInfo upfInfo = new UpLoadFileInfo(); upfInfo = ufDal.UpLoadFileGetInfo("Cm_Templet", TempletID); if (upfInfo != null && upfInfo.FileID != 0) { string path = AppDomain.CurrentDomain.BaseDirectory + upfInfo.FilePath + "\\" + upfInfo.UniqueName; Common.FileHandle.DeleteFile(path); if (ufDal.UpLoadFile_Del(upfInfo.FileID) != 1) { MessageBox.Show("操作失败。"); return; } } TempletInfo tinfo = dal.TempletGetInfo(TempletID); TempletTypeInfo tltinfo = menuDal.TempletTypeGetInfo(tinfo.ParentID); string fpath = CodeFile.GetFilePath(tltinfo); string filepath = AppDomain.CurrentDomain.BaseDirectory + fpath; rst = Common.FileHandle.WirteCreateFile(Content, filepath + "\\" + info.Title + "." + info.Postfix); if (rst == 1) { upfInfo.TableName = "Cm_Templet"; upfInfo.RootField = ""; upfInfo.RootId = ""; upfInfo.ParentField = ""; upfInfo.ParentId = TempletID.ToString(); upfInfo.FilePath = fpath; upfInfo.Remark = ""; upfInfo.FileSize = 0; upfInfo.FileName = info.Title; upfInfo.ExpandName = info.Postfix; upfInfo.UniqueName = info.Title + "." + info.Postfix; upfInfo.FileTypeId = tltinfo.ID; upfInfo.AttachmentId = tltinfo.Code; rst = ufDal.UpLoadFile_Add(upfInfo); } } QueryData(); if (rst == 1) { MessageBox.Show("保存成功。"); } else { MessageBox.Show("保存失败。"); } }