Example #1
0
        private void btn_sure_Click(object sender, EventArgs e)
        {
            String adminName = this.tbox_username.Text.Trim();
            String adminPwd  = this.tbox_password.Text.Trim();

            if ("".Equals(adminName) || "".Equals(adminPwd))
            {
                MessageBox.Show("请填写完整!");
            }
            else
            {
                System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider();
                byte[] output = md5.ComputeHash(Encoding.Default.GetBytes(adminPwd));
                string md5Pwd = BitConverter.ToString(output).Replace("-", "").ToLower();

                String   commandText_count = string.Format("SELECT count(*) count FROM FileAdmin where admin_name ='{0}' and admin_pwd='{1}'", adminName, md5Pwd);
                dBHelper helper            = new dBHelper(DBSource.ConnectionStringPBox);
                if (helper.Load(commandText_count, "") == true)
                {
                    DataTable dt_count = helper.DataSet.Tables[0];
                    int       count    = int.Parse(dt_count.Rows[0]["count"].ToString());
                    if (count > 0)
                    {
                        isAdmin            = true;
                        DBSource.ISAdmin   = isAdmin;
                        DBSource.AdminName = adminName;
                    }
                    else
                    {
                        isAdmin = false;
                    }
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
Example #2
0
 private void loadData()
 {
     if (DBSource.ISAdmin)
     {
         this.Invoke(new MethodInvoker(delegate {
             refreshTreeView();
         }));
         System.Threading.ThreadPool.QueueUserWorkItem((s) => refreshDataGridView());
     }
     else
     {
         //查询是否有密码设置,如果有弹出用户密码输入框,没有直接刷新显示
         String commandText_count = string.Format("SELECT count(*) count FROM FileAdmin");
         helperPBox = new dBHelper(DBSource.ConnectionStringPBox);
         if (helperPBox.Load(commandText_count, "") == true)
         {
             DataTable dt_count = helperPBox.DataSet.Tables[0];
             int       count    = int.Parse(dt_count.Rows[0]["count"].ToString());
             if (count > 0)
             {
                 //弹出用户密码输入框
                 FrmLoginAdmin frmInputPwd = new FrmLoginAdmin();
                 if (frmInputPwd.ShowDialog() == DialogResult.OK)
                 {
                     if (frmInputPwd.ISAdmin)
                     {
                         this.Invoke(new MethodInvoker(delegate {
                             refreshTreeView();
                         }));
                         System.Threading.ThreadPool.QueueUserWorkItem((s) => refreshDataGridView());
                     }
                     else
                     {
                         initDefDbPath();
                         MessageBoxEx.Show("非正确用户无法打开此箱子!   ", "解锁箱子");
                     }
                 }
                 else
                 {
                     MessageBoxEx.Show("非正确用户无法打开此箱子!   ", "解锁箱子");
                 }
             }
             else
             {
                 DBSource.ISAdmin   = true;
                 DBSource.AdminName = "匿名用户";
                 this.Invoke(new MethodInvoker(delegate {
                     refreshTreeView();
                 }));
                 System.Threading.ThreadPool.QueueUserWorkItem((s) => refreshDataGridView());
             }
         }
     }
     this.Text = "【私密箱:" + DBSource.AdminName + "】" + DBSource.ConnectionStringPBox.Replace("Data Source=", "");
 }
Example #3
0
 private void Dbgc()
 {
     this.Invoke(new MethodInvoker(delegate
     {
         imgLoadding.Visible = true;
     }));
     helperPBox  = new dBHelper(DBSource.ConnectionStringPBox);
     helperPData = new dBHelper(DBSource.ConnectionStringPData);
     helperPBox.Dbgc();
     helperPData.Dbgc();
     this.Invoke(new MethodInvoker(delegate
     {
         imgLoadding.Visible = false;
     }));
 }
Example #4
0
        private void refreshTreeView()
        {
            TreeNodeCollection nodes = this.treeView_nav.Nodes;

            nodes[0].Nodes.Clear();
            FileDBHelper imgHelper        = new FileDBHelper();
            string       connectionString = DBSource.ConnectionStringPBox;
            string       commandText      = @"SELECT * FROM FileNode ORDER BY disporder";

            helperPBox = new dBHelper(connectionString);
            if (helperPBox.Load(commandText, "") == true)
            {
                DataTable dataSource = helperPBox.DataSet.Tables[0];
                CreateTreeViewRecursive(nodes[0].Nodes, dataSource, 0);
            }
            this.treeView_nav.ExpandAll();
        }
Example #5
0
        private void buttonRight_Click_1(object sender, EventArgs e)
        {
            // button Delete
            // Determin the ConnectionString
            string connectionString = dBFunctions.ConnectionStringSQLite;

            // Determin the DataAdapter = CommandText + Connection
            string commandText = "SELECT * FROM Contact WHERE contact_id=" + contactId;

            // Make a new object
            helper = new dBHelper(connectionString);
            {
                // Load Data
                if (helper.Load(commandText, "contact_id") == true)
                {
                    // Determin if the row was found
                    if (helper.DataSet.Tables[0].Rows.Count == 1)
                    {
                        // Found, delete row
                        helper.DataSet.Tables[0].Rows[0].Delete();
                        try
                        {
                            // Save -> determin succes
                            if (helper.Save() == true)
                            {
                                deleteSucces = true;
                                MessageBox.Show("Delete succesfull");
                                this.Close();
                            }
                            else
                            {
                                deleteSucces = false;
                                MessageBox.Show("Delete failed");
                            }
                        }
                        catch (Exception ex)
                        {
                            // Show the Exception --> Dubbel ContactId/Name ?
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
Example #6
0
 private void refreshDataGridView()
 {
     try
     {
         int nodeID = -1;
         this.Invoke(new MethodInvoker(delegate {
             //loadding加载
             imgLoadding.Visible = true;
             if (treeView_nav.SelectedNode != null && int.Parse(treeView_nav.SelectedNode.Tag.ToString()) != 0)
             {
                 nodeID = int.Parse("" + treeView_nav.SelectedNode.Tag);
             }
         }));
         string connectionString  = DBSource.ConnectionStringPBox;
         string whereSql          = ("".Equals(this.textBox_search.Text.Trim())) ? "" : "and file_name like '%" + this.textBox_search.Text.Trim() + "%'";
         string commandText       = string.Format("select file_id,file_name,file_type,file_size,file_nodeid from FileMemo where 1=1 " + whereSql + " order by disporder limit {0},{1}", (pagerControl1.PageIndex - 1) * pagerControl1.PageSize, pagerControl1.PageSize);
         string commandText_count = "select count(*) totalCount from FileMemo where 1=1 " + whereSql;
         if (nodeID != -1)
         {
             commandText       = string.Format("SELECT file_id,file_name,file_type,file_size,file_nodeid FROM FileMemo where file_nodeid='" + nodeID + "' " + whereSql + " order by disporder limit {0},{1}", (pagerControl1.PageIndex - 1) * pagerControl1.PageSize, pagerControl1.PageSize);
             commandText_count = "select count(*) totalCount from FileMemo where file_nodeid='" + nodeID + "' " + whereSql;
         }
         helperPBox = new dBHelper(connectionString);
         if (helperPBox.Load(commandText_count, "") == true)
         {
             DataTable dt_count = helperPBox.DataSet.Tables[0];
             this.Invoke(new MethodInvoker(delegate {
                 pagerControl1.DrawControl(int.Parse(dt_count.Rows[0]["totalCount"].ToString()));
             }));
         }
         if (helperPBox.Load(commandText, "") == true)
         {
             this.Invoke(new MethodInvoker(delegate {
                 dataGridView_FileList.DataSource = helperPBox.DataSet.Tables[0];
             }));
         }
         this.Invoke(new MethodInvoker(delegate {
             imgLoadding.Visible = false;
         }));
     } catch (Exception exp) { }
 }
Example #7
0
        private void GetData()
        {
            // Determin the ConnectionString
            string connectionString = dBFunctions.ConnectionStringSQLite;

            // Determin the DataAdapter = CommandText + Connection
            string commandText = @"SELECT * FROM Contact WHERE contact_id =" + contactId;

            // Make a new object
            helper = new dBHelper(connectionString);

            // Load the data
            if (helper.Load(commandText, "") == true)
            {
                // Show the data in the datagridview
                dataRow                = helper.DataSet.Tables[0].Rows[0];
                base.textBoxId.Text    = dataRow[0].ToString();
                base.textBoxFName.Text = dataRow[1].ToString();
                base.textBoxLName.Text = dataRow[2].ToString();
            }
        }
Example #8
0
        private void GetData()
        {
            // Determin the ConnectionString
            string connectionString = dBFunctions.ConnectionStringSQLite;

            // Determin the DataAdapter = CommandText + Connection
            string commandText = @"SELECT * FROM Contact ORDER BY contact_id";

            // Make a new object
            helper = new dBHelper(connectionString);

            // Load the data
            if (helper.Load(commandText, "") == true)
            {
                // Show the data in the datagridview
                dataGridViewContactList.DataSource = helper.DataSet.Tables[0];
                listBox1.ValueMember   = "FirstName";
                listBox1.DisplayMember = "FirstName";
                listBox1.DataSource    = helper.DataSet;
            }
        }
Example #9
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Int32  fid = Convert.ToInt32(dataGridView_FileList.CurrentRow.Cells["file_id"].Value);
            string connectionStringPBox  = DBSource.ConnectionStringPBox;
            string connectionStringPData = DBSource.ConnectionStringPData;
            string commandText           = @"SELECT file_id,file_name,file_type,file_size,file_nodeid FROM FileMemo where file_id = " + fid;

            helperPBox = new dBHelper(connectionStringPBox);
            FileStream fs;

            if (helperPBox.Load(commandText, "") == true)
            {
                if (fid > 0 && helperPBox.DataSet.Tables[0].Rows.Count > 0)
                {
                    DataRow       dataRow    = helperPBox.DataSet.Tables[0].Select("file_id=" + fid)[0];
                    string        filename   = dataRow["file_name"].ToString();
                    string        filetype   = dataRow["file_type"].ToString();
                    List <Byte[]> l_fileData = new FileDBHelper().getFileData(fid);

                    this.saveFileDialog_File.Title      = "另存" + filename;
                    this.saveFileDialog_File.Filter     = filetype + "|" + filetype;
                    this.saveFileDialog_File.DefaultExt = filetype;
                    this.saveFileDialog_File.FileName   = filename;
                    if (this.saveFileDialog_File.ShowDialog() == DialogResult.OK)
                    {
                        FileInfo fi = new FileInfo(saveFileDialog_File.FileName);
                        fs = fi.OpenWrite();
                        for (int i = 0; i < l_fileData.Count; i++)
                        {
                            fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                        }
                        fs.Close();
                    }
                }
            }
        }
Example #10
0
        private void openFileViewer(Int32 fileID)
        {
            string connectionStringPBox  = DBSource.ConnectionStringPBox;
            string connectionStringPData = DBSource.ConnectionStringPData;
            string commandText           = @"SELECT file_id,file_name,file_type,file_size,file_nodeid FROM FileMemo where file_id = " + fileID;

            helperPBox = new dBHelper(connectionStringPBox);
            if (helperPBox.Load(commandText, "") == true)
            {
                if (fileID > 0 && helperPBox.DataSet.Tables[0].Rows.Count > 0)
                {
                    DataRow       dataRow    = helperPBox.DataSet.Tables[0].Select("file_id=" + fileID)[0];
                    string        filename   = dataRow["file_name"].ToString();
                    string        filetype   = dataRow["file_type"].ToString();
                    List <Byte[]> l_fileData = new FileDBHelper().getFileData(fileID);
                    if (l_fileData.Count == 0)
                    {
                        MessageBoxEx.Show("找不到对应数据文件!");
                        return;
                    }
                    SkinTabPage tp = new SkinTabPage();
                    tp.Text = filename;
                    switch (filetype)
                    {
                    case ".jpg":
                    case ".png":
                    case ".bmp":
                    case ".gif":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            try
                            {
                                Bitmap    bmap         = new Bitmap(Application.StartupPath + "\\temp\\" + filename + filetype);
                                PicViewer uc_picviewer = new PicViewer();
                                uc_picviewer.showPic(filename, bmap);
                                uc_picviewer.Dock = DockStyle.Fill;
                                tp.Controls.Add(uc_picviewer);
                                tabControl_Viewer.TabPages.Add(tp);
                            }
                            catch (Exception exp) { }
                        }
                        break;
                    }

                    case ".doc":
                    case ".docx":
                    case ".xls":
                    case ".xlsx":
                    case ".ppt":
                    case ".pptx":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            DocViewer uc_docviewer = new DocViewer();
                            tp.Tag            = uc_docviewer;
                            uc_docviewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(uc_docviewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            uc_docviewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".txt":
                    case ".sql":
                    case ".log":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            StreamReader sr        = new StreamReader(Application.StartupPath + "\\temp\\" + filename + filetype, Encoding.Default);
                            TxtViewer    txtViewer = new TxtViewer();
                            txtViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(txtViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            txtViewer.showTxt(sr.ReadToEnd());
                            sr.Close();
                        }
                        break;
                    }

                    case ".htm":
                    case ".html":
                    case ".mht":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            WebViewer webViewer = new WebViewer();
                            webViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(webViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            webViewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".pdf":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                            PDFViewer pdfViewer = new PDFViewer();
                            pdfViewer.Dock = DockStyle.Fill;
                            tp.Controls.Add(pdfViewer);
                            tabControl_Viewer.TabPages.Add(tp);
                            pdfViewer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        }
                        break;
                    }

                    case ".mp4":
                    case ".avi":
                    case ".rm":
                    case ".rmvb":
                    case ".flv":
                    case ".xr":
                    case ".wmv":
                    {
                        if (Directory.Exists(Application.StartupPath + "\\temp") == false)
                        {
                            Directory.CreateDirectory(Application.StartupPath + "\\temp");
                        }
                        FileStream fs;
                        FileInfo   fi = new FileInfo(Application.StartupPath + "\\temp\\" + filename + filetype);
                        if (!fi.Exists || !IsFileInUse(fi.FullName))
                        {
                            fs = fi.OpenWrite();
                            for (int i = 0; i < l_fileData.Count; i++)
                            {
                                fs.Write(l_fileData[i], 0, l_fileData[i].Length);
                            }
                            fs.Close();
                        }
                        FrmPlayer aplayer = new FrmPlayer();
                        aplayer.Text = filename;
                        aplayer.Show();
                        aplayer.openFile(Application.StartupPath + "\\temp\\" + filename + filetype);
                        break;
                    }
                    }
                    tabControl_Viewer.SelectedTab = tp;
                }
            }
        }
Example #11
0
        private void buttonRight_Click_1(object sender, EventArgs e)
        {
            if (base.textBoxFName.Text == string.Empty && base.textBoxLName.Text == string.Empty)
            {
                base.errorProviderBaseId.SetError(textBoxFName, "First Name required !");
                return;
            }
            else
            {
                base.errorProviderBaseId.SetError(textBoxId, string.Empty);
            }

            // Determin the ConnectionString
            string connectionString = dBFunctions.ConnectionStringSQLite;

            // Determin the DataAdapter = CommandText + Connection
            string commandText = "SELECT * FROM Contact WHERE contact_id=" + contactId;

            // Make a new object
            helper = new dBHelper(connectionString);
            {
                // Load Data
                if (helper.Load(commandText, "contact_id") == true)
                {
                    // Determin if the row was found
                    if (helper.DataSet.Tables[0].Rows.Count == 1)
                    {
                        // Determin the found row
                        DataRow dataRow = helper.DataSet.Tables[0].Rows[0];

                        // Modify the row
                        dataRow["FirstName"] = textBoxFName.Text;
                        dataRow["LastName"]  = textBoxLName.Text;

                        string updateText = "UPDATE contact SET FirstName ='" + textBoxFName.Text + "' WHERE contact_id='" + contactId + "'";
                        helper.setSqlCommand(updateText);


                        try
                        {
                            // Save -> determin succes
                            if (helper.Save() == true)
                            {
                                editSucces = true;
                                MessageBox.Show("Modification succesfull");
                                this.Close();
                            }
                            else
                            {
                                editSucces = false;
                                MessageBox.Show("Modification failed");
                            }
                        }
                        catch (Exception ex)
                        {
                            // Show the Exception --> Dubbel ContactId/Name ?
                            MessageBox.Show(ex.Message);
                        }
                    }
                }//END IF
            }
        }
Example #12
0
        private void buttonRight_Click_1(object sender, EventArgs e)
        {
            int i = 0;

            if (textBoxId.Text != string.Empty)
            {
                i = Convert.ToInt32(textBoxId.Text);
            }

            if (i > 0)
            {
                base.errorProviderBaseId.SetError(textBoxId, "Contact_Id already exists");
                return;
            }
            else
            {
                base.errorProviderBaseId.SetError(textBoxId, string.Empty);
            }

            if (base.textBoxFName.Text == string.Empty && base.textBoxLName.Text == string.Empty)
            {
                base.errorProviderBaseId.SetError(textBoxFName, "First Name required !");
                return;
            }
            else
            {
                base.errorProviderBaseId.SetError(textBoxId, string.Empty);
            }


            // Determin the ConnectionString
            string connectionString = dBFunctions.ConnectionStringSQLite;

            // Determin the DataAdapter = CommandText + Connection
            string commandText = "SELECT * FROM Contact WHERE 1=0";

            // Make a new object
            helper = new dBHelper(connectionString);
            {
                // Load Data
                if (helper.Load(commandText, "contact_id") == true)
                {
                    // Add a row and determin the row
                    helper.DataSet.Tables[0].Rows.Add(helper.DataSet.Tables[0].NewRow());
                    DataRow dataRow = helper.DataSet.Tables[0].Rows[0];

                    // Enter the given values
                    dataRow["FirstName"] = textBoxFName.Text;
                    dataRow["LastName"]  = textBoxLName.Text;

                    try
                    {
                        // Save -> determin succes
                        if (helper.Save() == true)
                        {
                            textBoxId.Text = dataRow["contact_id"].ToString();
                            insertSucces   = true;
                            this.Close();
                        }
                        else
                        {
                            insertSucces = false;
                            MessageBox.Show("Error during Insertion");
                        }
                    }
                    catch (Exception ex)
                    {
                        // Show the Exception --> Dubbel ContactId/Name ?
                        MessageBox.Show(ex.Message);
                    }
                }//END IF
            }
        }