Пример #1
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);
                }
            }
        }
Пример #2
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();
                }
            }
        }