Example #1
0
        //数据库交换次序
        private void ChangeTrunById(string NodeId1, string NodeId2)
        {
            string SQL   = "select turn from ttree where nodeid=" + NodeId1;
            string Turn1 = AccessAdo.ExecuteScalar(SQL, null).ToString();

            SQL = "select turn from ttree where nodeid=" + NodeId2;
            string Turn2 = AccessAdo.ExecuteScalar(SQL, null).ToString();

            SQL = string.Format("update ttree set turn={0} where nodeid={1}", Turn2, NodeId1);
            try
            {
                AccessAdo.ExecuteNonQuery(SQL, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            SQL = string.Format("update ttree set turn={0} where nodeid={1}", Turn1, NodeId2);

            try
            {
                AccessAdo.ExecuteNonQuery(SQL, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #2
0
        private void treeViewDir_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (treeViewDir.SelectedNode == null)
            {
                return;
            }

            int iType = treeViewDir.SelectedNode.ImageIndex;

            if (iType == 0)
            {
                //双击目录
            }
            else
            {
                //双击文章,如果已经打开,则定位,否则新窗口打开
                string sNodeId = treeViewDir.SelectedNode.Tag.ToString();
                formParent.openNew(sNodeId);

                //打开后设置语言
                string Language = AccessAdo.ExecuteScalar("select synid from ttree where nodeid=" + sNodeId).ToString();
                Language = PubFunc.Synid2LanguageSetLang(Language);
                formParent.SetLanguage(Language);
            }
        }
Example #3
0
        //保存当前文章
        public void Save()
        {
            string DocText = this.scintilla1.Text;

            if (DocText.Length == 0)
            {
                return;
            }

            OleDbParameter p1 = new OleDbParameter("@Content", OleDbType.VarChar);

            p1.Value = DocText;
            OleDbParameter p2 = new OleDbParameter("@NodeId", OleDbType.Integer);

            p2.Value = Convert.ToInt32(this.NodeId);

            OleDbParameter[] ArrPara = new OleDbParameter[2];
            ArrPara[0] = p1;
            ArrPara[1] = p2;
            string SQL = "update tcontent set content=@Content where NodeId=@NodeId";

            AccessAdo.ExecuteNonQuery(SQL, ArrPara);

            scintilla1.Modified = false;
        }
Example #4
0
        private DataTable GetTable(string SQL)
        {
            DataSet   ds = AccessAdo.ExecuteDataSet(SQL);
            DataTable dt = ds.Tables[0];

            return(dt);
        }
Example #5
0
        private DocumentForm OpenFile(string nodeId)
        {
            //获取文章信息
            string    SQL  = "select Title,Content from TContent inner join TTree on TContent.NodeId=Ttree.NodeId where TContent.NodeId=" + nodeId;
            DataTable temp = AccessAdo.ExecuteDataSet(SQL, null).Tables[0];

            if (temp.Rows.Count == 0)
            {
                return(null);
            }
            string Title   = temp.Rows[0]["Title"].ToString();
            string Content = temp.Rows[0]["Content"].ToString();

            DocumentForm doc = new DocumentForm();

            SetScintillaToCurrentOptions(doc);
            doc.Scintilla.Text = Content;
            doc.Scintilla.UndoRedo.EmptyUndoBuffer();
            doc.Scintilla.Modified = false;
            doc.Text   = Title;
            doc.NodeId = nodeId;
            doc.Show(dockPanel1);


            return(doc);
        }
Example #6
0
        //刷新附件
        public void ReFreshAttachGrid()
        {
            DataView dv = new DataView(AccessAdo.ExecuteDataSet("select affixid,nodeid,'' as 序号,[title] as 标题,[size] as 大小,[time] as 加入日期 from tattachment where nodeid=" + Attachment.ActiveNodeId).Tables[0]);

            dataGridView1.DataSource         = dv;
            dataGridView1.Columns[0].Visible = false;
            dataGridView1.Columns[1].Visible = false;

            int count = dv.Count;

            for (int i = 0; i < count; i++)
            {
                dataGridView1.Rows[i].Cells[2].Value = i + 1;
            }
        }
Example #7
0
        //另存为
        private void toolStripMenuItemSaveAs_Click(object sender, EventArgs e)
        {
            string Affixid = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            string Title   = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();

            byte[] TempData = (byte[])AccessAdo.ExecuteScalar("select data from tattachment where affixid=" + Affixid);

            string         Path;
            SaveFileDialog sf = new SaveFileDialog();

            sf.FileName = Title;
            //设置文件类型
            sf.Filter = "All files(*.*)|*.*";
            if (sf.ShowDialog() == DialogResult.OK)
            {
                Path = sf.FileName;
                FileStream fs = new FileStream(Path, FileMode.Create);
                fs.Write(TempData, 0, TempData.Length);
            }
        }
Example #8
0
        //删除数据库记录,同时关闭已打开的文章
        public void DelNodeData(string NodeId)
        {
            string    SQL  = string.Format("select NodeId from Ttree where parentId={0}", NodeId);
            DataTable temp = AccessAdo.ExecuteDataSet(SQL).Tables[0];
            DataView  dv   = new DataView(temp);

            foreach (DataRowView drv in dv)
            {
                DelNodeData(drv["NodeId"].ToString());
            }

            //关闭打开的文章
            formParent.CloseDoc(NodeId);

            string DelSQL = string.Format("Delete from TAttachment where NodeId={0}", NodeId);

            AccessAdo.ExecuteNonQuery(DelSQL);
            DelSQL = string.Format("Delete from Tcontent where NodeId={0}", NodeId);
            AccessAdo.ExecuteNonQuery(DelSQL);
            DelSQL = string.Format("Delete from Ttree where NodeId={0}", NodeId);
            AccessAdo.ExecuteNonQuery(DelSQL);
        }
Example #9
0
        //新建文章
        private void toolStripMenuItemNewTxt_Click(object sender, EventArgs e)
        {
            //获取选中节点
            TreeNode SeleNode = treeViewDir.SelectedNode;

            if (SeleNode == null)
            {
                return;
            }
            string ParLang = AccessAdo.ExecuteScalar("select SynId from ttree where NodeId=" + SeleNode.Tag.ToString()).ToString();

            ParLang = PubFunc.Synid2Language(ParLang);
            ProperDialog propDia = new ProperDialog("1", "", ParLang);
            DialogResult dr      = propDia.ShowDialog();

            if (dr == DialogResult.OK)
            {
                string Title    = propDia.ReturnVal[0];
                string Language = propDia.ReturnVal[1];
                string IsOnRoot = propDia.ReturnVal[2];
                string SynId    = PubFunc.Language2Synid(Language);

                if (SeleNode != null)
                {
                    string NewPid    = SeleNode.Tag.ToString();
                    string NewNodeId = AccessAdo.ExecuteScalar("select max(NodeId) from ttree").ToString();
                    NewNodeId = NewNodeId == "" ? "1" : (Convert.ToInt32(NewNodeId) + 1).ToString();
                    string NewTurn = AccessAdo.ExecuteScalar("select max(Turn) from ttree where parentId=" + NewPid).ToString();
                    NewTurn = NewTurn == "" ? "1" : (Convert.ToInt32(NewTurn) + 1).ToString();

                    //顶层
                    if (IsOnRoot == "True")
                    {
                        NewPid  = "0";
                        NewTurn = AccessAdo.ExecuteScalar("select max(Turn) from ttree where parentId=0").ToString();
                        NewTurn = NewTurn == "" ? "1" : (Convert.ToInt32(NewTurn) + 1).ToString();
                    }

                    //插入数据库记录
                    DateTime d1 = DateTime.Parse("1970-01-01 08:00:00");
                    DateTime d2 = DateTime.Now;
                    TimeSpan dt = d2 - d1;
                    //相差秒数
                    string Seconds = dt.Seconds.ToString();
                    //插入TTREE
                    string sql = string.Format("insert into ttree(NodeID,Title,ParentId,Type,CreateTime,SynId,Turn) values({0},'{1}',{2},{3},{4},{5},{6})", NewNodeId, Title, NewPid, 1, Seconds, SynId, NewTurn);
                    AccessAdo.ExecuteNonQuery(sql);
                    //插入TTcontent
                    sql = string.Format("insert into tcontent(NodeId) values({0})", NewNodeId);
                    AccessAdo.ExecuteNonQuery(sql);

                    //插入树节点
                    TreeNode InsertNodeDoc = new TreeNode(Title);
                    InsertNodeDoc.Tag                = NewNodeId;
                    InsertNodeDoc.ImageIndex         = 1;
                    InsertNodeDoc.SelectedImageIndex = 1;
                    if (IsOnRoot == "True")
                    {
                        treeViewDir.Nodes.Insert(treeViewDir.Nodes.Count, InsertNodeDoc);
                    }
                    else
                    {
                        SeleNode.Nodes.Insert(SeleNode.Nodes.Count, InsertNodeDoc);
                    }

                    //新窗口打开编辑界面
                    formParent.openNew(NewNodeId);

                    //打开后设置语言
                    Language = PubFunc.Synid2LanguageSetLang(SynId);
                    formParent.SetLanguage(Language);
                }
            }
        }
Example #10
0
        //添加附件
        private void toolStripMenuItemAddZIP_Click(object sender, EventArgs e)
        {
            Stream         myStream;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            //openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "All files (*.*)|*.*";
            openFileDialog1.RestoreDirectory = false;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string fileName = openFileDialog1.FileName;
                if ((myStream = openFileDialog1.OpenFile()) != null)
                {
                    // Insert code to read the stream here.
                    FileStream fs   = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                    byte[]     data = new byte[fs.Length];
                    fs.Read(data, 0, (int)fs.Length);

                    int Datalength = (int)fs.Length;
                    fs.Close();

                    string NewAffixid    = AccessAdo.ExecuteScalar("select max(affixid) from tattachment").ToString();
                    int    intNewAffixid = NewAffixid == "" ? 1 : Convert.ToInt32(NewAffixid) + 1;

                    int    Nodeid      = Convert.ToInt32(Attachment.ActiveNodeId);
                    string Title       = openFileDialog1.SafeFileName;
                    int    timeSeconds = PubFunc.time2TotalSeconds();

                    //affixid
                    OleDbParameter p1 = new OleDbParameter("@affixid", OleDbType.Integer);
                    p1.Value = intNewAffixid;
                    //nodeid
                    OleDbParameter p2 = new OleDbParameter("@nodeid", OleDbType.Integer);
                    p2.Value = Nodeid;
                    //title
                    OleDbParameter p3 = new OleDbParameter("@title", OleDbType.VarChar);
                    p3.Value = Title;
                    //二进制数据
                    OleDbParameter p4 = new OleDbParameter("@Data", OleDbType.Binary);
                    p4.Value = data;
                    //size
                    OleDbParameter p5 = new OleDbParameter("@size", OleDbType.Integer);
                    p5.Value = Datalength;
                    //time
                    OleDbParameter p6 = new OleDbParameter("@time", OleDbType.Integer);
                    p6.Value = timeSeconds;

                    OleDbParameter[] arrPara = new OleDbParameter[6];
                    arrPara[0] = p1;
                    arrPara[1] = p2;
                    arrPara[2] = p3;
                    arrPara[3] = p4;
                    arrPara[4] = p5;
                    arrPara[5] = p6;
                    string SQL = "insert into tattachment values(@affixid,@nodeid,@title,@Data,@size,@time)";
                    AccessAdo.ExecuteNonQuery(SQL, arrPara);

                    myStream.Close();

                    ReFreshAttachGrid();
                }
            }
        }
Example #11
0
 private void FormAttachment_Load(object sender, EventArgs e)
 {
     dataGridView1.DataSource = AccessAdo.ExecuteDataSet("select '' as 序号,[title] as 标题,[size] as 大小,[time] as 加入日期 from tattachment where nodeid=" + Attachment.ActiveNodeId).Tables[0];
 }