Beispiel #1
0
        /// <summary>
        /// Merge trees in the database to new tree, return new tree Name
        /// </summary>
        /// <param name="inLstTreeIds" type="List<string>">
        /// <returns String>
        public static String merge_Trees(List <string> inLstTreeIds)
        {
            int i = 0;
            //merge trees in the database to new tree, return new tree Name
            string strMsg = "Error: Tree Merge failed.";
            //generate new guid for new tree
            string strNewTreeId = Guid.NewGuid().ToString();

            try
            {
                DTO.DocTree outDocFolder = new DTO.DocTree();
                //first 2 items are New tree name & New tree comment
                outDocFolder.TreeName       = inLstTreeIds[0];
                outDocFolder.TreeComment    = inLstTreeIds[1];
                outDocFolder.TreeId         = strNewTreeId;
                outDocFolder.TreeCreateDate = DateTime.Now.ToString();
                //first save tree, then all leafs
                save_One_New_Tree(outDocFolder);
                //copy all old tree leafs to new tree id in db
                //foreach (String strTId in inLstTreeIds)
                for (i = 2; i < inLstTreeIds.Count; i++)  //loop through each string old-tree id
                {
                    if (inLstTreeIds[i].Length == 36)
                    {
                        //get all leafs for this old-tree
                        DataTable dtTreeLeafs = get_Leafs_By_TreeId(inLstTreeIds[i].ToString());
                        //loop through leafs
                        foreach (DataRow dr in dtTreeLeafs.Rows)
                        {
                            //change to new-tree id
                            dr["treeId"] = strNewTreeId;
                            //build dto from dt
                            DTO.DocTree newDocTree = build_Tree_Row(dr);
                            //save this leaf for the new-tree to new-tree id with new dto
                            strMsg = save_One_New_Leaf(newDocTree);
                        }
                    }
                }
                strMsg = string.Format("Tree merge successful ({0}). Ready.", strNewTreeId);
            }
            catch (Exception ex)
            {
                strMsg = "Save error (" + i.ToString() + "): " + ex.Message + ".";
            }
            return(strMsg);
        }
Beispiel #2
0
 public static DTO.DocTree build_Leaf_Row(DataRow inLeafDr)
 {
     DTO.DocTree newDocFold = new DTO.DocTree
     {
         TreeId          = inLeafDr["treeId"].ToString() ?? string.Empty,
         LeafId          = inLeafDr["leafId"].ToString() ?? string.Empty,
         LeafName        = inLeafDr["leafName"].ToString() ?? string.Empty,
         LeafCreated     = inLeafDr["leafCreateDate"].ToString() ?? string.Empty,
         LeafCreatUser   = inLeafDr["leafCreateUser"].ToString() ?? string.Empty,
         LeafPath        = inLeafDr["leafPath"].ToString() ?? string.Empty,
         LeafSize        = inLeafDr["leafSize"].ToString() ?? string.Empty,
         LeafCategory    = inLeafDr["leafCategory"].ToString() ?? string.Empty,
         LeafSubCategory = inLeafDr["leafSubCategory"].ToString() ?? string.Empty,
         LeafLocation    = inLeafDr["leafLocation"].ToString() ?? string.Empty,
         LeafType        = inLeafDr["leafType"].ToString() ?? string.Empty,
         LeafComment     = inLeafDr["leafComment"].ToString() ?? string.Empty,
         LeafViewed      = inLeafDr["leafViewed"].ToString() ?? string.Empty
     };
     return(newDocFold);
 }
Beispiel #3
0
        /// <summary>
        /// Updates 1 leaf by leafId
        /// </summary>
        /// <param name="inDocFolder" type="DTO.DocTree">
        /// <returns String>
        public static String update_Leaf(DTO.DocTree inDocFolder)
        {
            int i = 0;
            //save one folder document object/row to the database
            string strMsg = "Leaf Update failed (Leaf Id: " + inDocFolder.LeafId + ").";

            inDocFolder.LeafPath = inDocFolder.LeafPath.Replace("\\", "\\\\");
            try
            {
                string constr = ConfigurationManager.ConnectionStrings["flMySql"].ConnectionString;
                using (MySqlConnection conn = new MySqlConnection(constr))
                {
                    MySqlCommand cmd = new MySqlCommand("update_leaf", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("ivarTreeId", inDocFolder.TreeId);
                    cmd.Parameters.AddWithValue("ivarLeafId", inDocFolder.LeafId);
                    cmd.Parameters.AddWithValue("ivarLeafName", inDocFolder.LeafName);
                    cmd.Parameters.AddWithValue("ivarLeafSize", inDocFolder.LeafSize);
                    cmd.Parameters.AddWithValue("ivarLeafPath", inDocFolder.LeafPath);
                    cmd.Parameters.AddWithValue("ivarLeafCreateDate", inDocFolder.LeafCreated);
                    cmd.Parameters.AddWithValue("ivarLeafCreateUser", inDocFolder.LeafCreatUser);
                    cmd.Parameters.AddWithValue("ivarLeafCategory", inDocFolder.LeafCategory);
                    cmd.Parameters.AddWithValue("ivarLeafSubCategory", inDocFolder.LeafSubCategory);
                    cmd.Parameters.AddWithValue("ivarLeafLocation", inDocFolder.LeafLocation);
                    cmd.Parameters.AddWithValue("ivarLeafType", inDocFolder.LeafType);
                    cmd.Parameters.AddWithValue("ivarLeafComment", inDocFolder.LeafComment);
                    cmd.Parameters.AddWithValue("ivarLeafViewed", inDocFolder.LeafViewed);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
            }
            catch (MySqlException sex)
            {
                strMsg = "Update Leaf SQL error: " + sex.Message + ".";
            }
            catch (Exception ex)
            {
                strMsg = "Update Leaf error: " + ex.Message + ".";
            }
            return(strMsg);
        }
Beispiel #4
0
        /// <summary>
        /// Get only 1 tree (and leafs) from db by treeId
        /// </summary>
        /// <param name="inTreeId" type="String">
        /// <param name="inLeafId" type="String">
        /// <returns DTO.DocTree>
        public static DTO.DocTree get_Leaf_By_LeafId_By_TreeId(string inLeafId, string inTreeId)
        {
            //get only 1 tree from db by Tree Id
            string strMsg = "Error: Get Leaf (" + inLeafId + ") failed.";

            DTO.DocTree docTree = new DTO.DocTree();
            try
            {
                string constr = ConfigurationManager.ConnectionStrings["flMySql"].ConnectionString;
                using (MySqlConnection conn = new MySqlConnection(constr))
                {
                    using (MySqlCommand cmd = new MySqlCommand("get_Leaf_By_LeafId_By_TreeId", conn))
                    {
                        using (MySqlDataAdapter sda = new MySqlDataAdapter())
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("ivarLeafId", inLeafId);
                            cmd.Parameters.AddWithValue("ivarTreeId", inTreeId);
                            sda.SelectCommand = cmd;
                            using (DataTable dt = new DataTable())
                            {
                                sda.Fill(dt);
                                if (dt.Rows.Count > 0)
                                {
                                    foreach (DataRow row in dt.Rows)
                                    {
                                        docTree = build_Tree_Row(row);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                strMsg = "Fetch & view error: " + ex.Message + ".";
            }
            return(docTree);
        }
Beispiel #5
0
        public static String save_One_New_Tree(DTO.DocTree inDocFolder)
        {
            int i = 0;
            //save one folder document object/row to the database
            string strMsg = "Folder Document Insert failed.";

            inDocFolder.TreeRoot = inDocFolder.TreeRoot.Replace("\\", "\\\\");
            //first check if tree (id) already exists, if so just save leaf with existing tree id
            if (!tree_Exists(inDocFolder.TreeId))
            {
                //tree not exist, create new tree
                try
                {
                    string constr = ConfigurationManager.ConnectionStrings["flMySql"].ConnectionString;
                    using (MySqlConnection conn = new MySqlConnection(constr))
                    {
                        MySqlCommand cmd = new MySqlCommand("save_one_new_tree", conn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("ivarTreeId", inDocFolder.TreeId);
                        cmd.Parameters.AddWithValue("ivarTreeName", inDocFolder.TreeName);
                        cmd.Parameters.AddWithValue("ivarRootPath", inDocFolder.TreeRoot);
                        cmd.Parameters.AddWithValue("ivarTreeCreateDate", inDocFolder.TreeCreateDate);
                        cmd.Parameters.AddWithValue("ivarTreeComment", inDocFolder.TreeComment);
                        cmd.Parameters.AddWithValue("ivarTreeType", inDocFolder.TreeType);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (MySqlException sex)
                {
                    strMsg = "Save Tree SQL error: " + sex.Message + ".";
                }
                catch (Exception ex)
                {
                    strMsg = "Save Tree error: " + ex.Message + ".";
                }
            }
            return(strMsg);
        }
Beispiel #6
0
 private void dgvTreeList_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         string viewLeafId = dgvTreeList[12, e.RowIndex].Value.ToString();
         editLeaf = DAL.get_Leaf_By_LeafId(viewLeafId);
         if (!string.IsNullOrEmpty(viewLeafId))
         {
             txtLeafId.Text = editLeaf.LeafId.ToString();
             if (!string.IsNullOrEmpty(editLeaf.LeafViewed))
             {
                 if (editLeaf.LeafViewed == "false")
                 {
                     chkLeafViewed.Checked = false;
                 }
                 else
                 {
                     chkLeafViewed.Checked = true;
                 }
             }
             else
             {
                 chkLeafViewed.Checked = false;
             }
             cboLeafCategory.Text = editLeaf.LeafCategory;
             cboLeafSubCat.Text   = editLeaf.LeafSubCategory;
             txtLeafLocation.Text = editLeaf.LeafLocation;
             cboLeafType.Text     = editLeaf.LeafType;
             txtLeafComment.Text  = editLeaf.LeafComment;
             txtLeafName.Text     = editLeaf.LeafName;
         }
     }
     catch (Exception ex)
     {
         string crap = "yup";
     }
 }
Beispiel #7
0
        private void load_Lv(string inTreePath)
        {
            string[] filesToImport;
            try
            {
                int iCnt = 0;
                //set up the list view
                lvFiles.Clear();
                lvFiles.Columns.Add("Name", -2, HorizontalAlignment.Left);
                lvFiles.Columns[0].Width = 300;
                //lvFiles.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                lvFiles.Columns.Add("Size", -2, HorizontalAlignment.Right);
                if (!Util.FileOrDirectoryExists(txtRootPath.Text))
                {
                    lblStat.Text = string.Format("Invalid tree root path (" + txtRootPath.Text + "). Ready.");
                    return;
                }
                string selectedPath = txtRootPath.Text;
                txtRootPath.Text = selectedPath;
                if (chkFiles.Checked)
                {
                    filesToImport = Directory.GetFiles(selectedPath, "*", SearchOption.AllDirectories);
                }
                else
                {
                    filesToImport = Directory.GetDirectories(selectedPath, "*", SearchOption.AllDirectories);
                }
                Array.Sort(filesToImport);

                if (filesToImport.Count() > 100)
                {
                    if (MessageBox.Show("Tree size very big (" + filesToImport.Count().ToString() + "). Are you sure you want to save ALL these?", "File Lister", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                    {
                        return;
                    }
                }
                string strTreeId         = Guid.NewGuid().ToString();
                string strTreeCreateDate = DateTime.UtcNow.ToString();
                //got path, iterate folders
                foreach (var filePath in filesToImport)
                {
                    iCnt++;
                    var file = new FileInfo(filePath);

                    string[] treePath = filePath.Replace(selectedPath, "").Split('\\');

                    var    folderSize   = GetDirectorySize(filePath);
                    long   len          = GetDirectorySize(filePath);
                    string readableSize = Util.GetBytesReadable(len);

                    DTO.DocTree newDocFold = new DTO.DocTree
                    {
                        TreeId         = strTreeId,
                        TreeName       = txtTreeName.Text,
                        TreeCreateDate = strTreeCreateDate,
                        TreeComment    = txtComment.Text,
                        TreeRoot       = selectedPath,
                        LeafId         = Guid.NewGuid().ToString(),
                        LeafName       = file.Name.Replace("'", ""),
                        LeafCreated    = file.CreationTime.ToString(),
                        LeafCreatUser  = file.FullName,
                        LeafPath       = file.Directory.ToString(),
                        LeafSize       = readableSize,
                        LeafCategory   = "Imported",
                        LeafType       = "Folder",
                        LeafComment    = "Autogen"
                    };

                    var lvFolder = new ListViewItem(new[] { newDocFold.LeafName, newDocFold.LeafSize });
                    lvFolder.Tag = newDocFold;
                    lvFiles.Items.Add(lvFolder);
                }
                Application.DoEvents();
                lblStat.Text = "Done getting folder list (" + iCnt.ToString() + "). Ready.";
            }
            catch (Exception ex)
            {
                lblStat.Text = "Error saving tree to DB: " + ex.Message + ".";
            }
        }
Beispiel #8
0
 public frmMain()
 {
     InitializeComponent();
     editLeaf = null;
 }
Beispiel #9
0
        private string saveTreeToDb()
        {
            //save tree to db
            string strRetMsg = "Save to DB failed.";

            string[] filesToImport;
            try
            {
                //set up treeview

                //now do listview stuff
                int iCnt = 0;
                //set up the list view
                lvFiles.Clear();
                lvFiles.Columns.Add("Name", -2, HorizontalAlignment.Left);
                lvFiles.Columns[0].Width = 300;
                //lvFiles.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                lvFiles.Columns.Add("Size", -2, HorizontalAlignment.Left);
                if (!Util.FileOrDirectoryExists(txtRootPath.Text))
                {
                    strRetMsg = String.Format("Invalid tree root path (" + txtRootPath.Text + "). Ready.");
                    return(strRetMsg);
                }
                if (string.IsNullOrEmpty(txtTreeName.Text))
                {
                    DateTime dt = DateTime.UtcNow;
                    txtTreeName.Text = String.Format("Default Tree Name_{0}", dt.ToString("yyyyMMddHHMMss"));
                }
                string selectedPath = txtRootPath.Text.Replace("'", "");
                txtRootPath.Text = selectedPath;
                if (chkFiles.Checked)
                {
                    filesToImport = Directory.GetFiles(selectedPath, "*", SearchOption.AllDirectories);
                }
                else
                {
                    filesToImport = Directory.GetDirectories(selectedPath, "*", SearchOption.AllDirectories);
                }
                string strTreeId         = Guid.NewGuid().ToString();
                string strTreeCreateDate = DateTime.UtcNow.ToString();
                txtTreeId.Text = strTreeId;
                //first save the new tree
                DTO.DocTree inDocTree = new DTO.DocTree
                {
                    TreeId         = strTreeId,
                    TreeName       = txtTreeName.Text,
                    TreeRoot       = selectedPath,
                    TreeCreateDate = strTreeCreateDate,
                    TreeComment    = txtComment.Text,
                    TreeType       = "Video"
                };
                lblStat.Text = "Saving Tree to db . . .";
                Application.DoEvents();
                strRetMsg = DAL.save_One_New_Tree(inDocTree);
                //got path, iterate folders
                foreach (var filePath in filesToImport)
                {
                    iCnt++;
                    var file = new FileInfo(filePath);

                    string[] treePath   = filePath.Replace(selectedPath, "").Split('\\');
                    var      folderSize = GetDirectorySize(filePath);
                    var      folderName = file.Name.Replace("'", "").Replace(",", "_");

                    DTO.DocTree newDocFold = new DTO.DocTree
                    {
                        TreeId          = strTreeId,
                        TreeName        = txtTreeName.Text,
                        TreeCreateDate  = strTreeCreateDate,
                        TreeComment     = txtComment.Text,
                        TreeType        = Guid.NewGuid().ToString(),
                        TreeRoot        = selectedPath.Replace("'", ""),
                        LeafId          = Guid.NewGuid().ToString(),
                        LeafName        = folderName,
                        LeafCreated     = file.CreationTime.ToString(),
                        LeafCreatUser   = file.FullName.Replace("'", ""),
                        LeafPath        = file.Directory.ToString().Replace("'", ""),
                        LeafSize        = folderSize.ToString(),
                        LeafCategory    = "Imported",
                        LeafSubCategory = "None",
                        LeafLocation    = txtLocation.Text,
                        LeafType        = "Video",
                        LeafViewed      = "false",
                        LeafComment     = txtLeafComment.Text
                    };
                    //save the new leaf
                    strRetMsg = DAL.save_One_New_Leaf(newDocFold);
                    //add the leaf to the listview
                    var lvFolder = new ListViewItem(new[] { newDocFold.LeafName, newDocFold.LeafSize });
                    lvFolder.Tag = newDocFold;
                    lvFiles.Items.Add(lvFolder);
                    lblStat.Text = lblStat.Text + " .";
                    Application.DoEvents();
                }
                //completed tree & leaf save operation
                Application.DoEvents();
                lblStat.Text = "Done saving Tree and Leaf's (" + iCnt.ToString() + "). Ready.";
            }
            catch (Exception ex)
            {
                lblStat.Text = "Error saving tree to DB: " + ex.Message + ".";
            }
            return(strRetMsg);
        }