Un Arbolito


Este es el codigo de un sistema q trabaje una semana, se usa para modificar los archivos de un servidor desde una pagina web, no pude pegar todo el codigo pero auqui esta la funcion principal:
 
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)

    {

        //TODO:Copia de los valores del archivo actual;

        FileData tempData = new FileData();

        checksum.ClassCheckSumFile chksumFile = new checksum.ClassCheckSumFile(this.ChecksumFilePath);

        bool Exists = false;

       

        tempData.week = this.txtWeek.Text;       

        tempData.year = this.txtYear.Text;

        //if the year is for in the full value:2006

        if (tempData.year.Length > 2)

            tempData.year = tempData.year.Substring(2,2);

        else if (tempData.year.Length < 2)

            tempData.year = "0"+ tempData.year;

 

        if (this.CheckBox1.Checked)

            this.txtFileName.Text = tempData.week + "_" + tempData.year + "_" + this.txtFileName.Text;

 

        tempData.filename = this.txtFileName.Text;

        tempData.supplier = this.DropDownListSupplier.SelectedValue;

 

        TreeNode selectedNode = TreeView1.SelectedNode;

        if (selectedNode != null)

        {

            TreeNode topnode = selectedNode;

            //searching the root Node

            while (topnode.Parent != null) topnode = topnode.Parent;

            //construction the destination path form the text box typed by the user

            string newPath = this.Path + tempData.supplier + "\\" + tempData.week + " " + tempData.year + "\\";

            string OldPath = "";

            //constructing the source path

            if (ODMFile.week!=null)

                OldPath = this.Path + ODMFile.supplier + "\\" + ODMFile.week + " " + ODMFile.year + "\\";

            else

                OldPath = this.Path + ODMFile.supplier + "\\Unassigned\\";

            //if the destination path dont exists,create it.

            if (!Directory.Exists(newPath))

                Directory.CreateDirectory(newPath);

            //if there is no error, continue

            if (Directory.Exists(newPath))

            {  //moving the file

 

                Exists = File.Exists(newPath + tempData.filename);

 

                if ((OldPath != newPath) && (ODMFile.filename == tempData.filename) && (Exists))

                {

                    chksumFile.AddRecord(OldPath, new FileInfo(OldPath + ODMFile.filename), "navigator", checksum.ClassCheckSumFile.Action.REMOVED);

                    chksumFile.AddRecord(newPath, new FileInfo(newPath + tempData.filename), "navigator", checksum.ClassCheckSumFile.Action.REPLACED);

                }

               

                if ((OldPath != newPath) && (ODMFile.filename == tempData.filename) && (!Exists))

                    chksumFile.AddRecord(OldPath, new FileInfo(OldPath + ODMFile.filename), navigatorma, checksum.ClassCheckSumFile.Action.REMOVED);

                if (OldPath + ODMFile.filename != newPath + tempData.filename)

                {

                    if (Exists)

                        File.Move(newPath + tempData.filename, this.DeletedPath + DateTime.Now.Ticks.ToString() + "-" + tempData.filename);

 

                    File.Move(OldPath + ODMFile.filename, newPath + tempData.filename);

                }

                else

                {

                    return;

                }

                if ((OldPath != newPath) && (ODMFile.filename == tempData.filename) && (!Exists))

                    chksumFile.AddRecord(newPath, new FileInfo(newPath + ODMFile.filename), "navigator", checksum.ClassCheckSumFile.Action.MOVED);

 

                if (ODMFile.filename != tempData.filename)

                    chksumFile.AddRecord(newPath, new FileInfo(newPath + tempData.filename), "navigator", checksum.ClassCheckSumFile.Action.MOVED);

 

                //remaning file

                //refresing the tree,

                TreeNode UpdatedNode = this.TreeView1.FindNode(Server.HtmlEncode(selectedNode.ValuePath));

                TreeNode childNode=new TreeNode();

                UpdatedNode.Parent.ChildNodes.Remove(UpdatedNode);

                //search the week

                UpdatedNode = this.TreeView1.FindNode(Server.HtmlEncode("folder:" + tempData.supplier + "\\" + "folder:" + tempData.week + " " + tempData.year ));                //this.TreeView1.Nodes.Clear();

                //if the week not exist, add it

                if (UpdatedNode == null)

                {

                    UpdatedNode = this.TreeView1.FindNode(Server.HtmlEncode("folder:" + tempData.supplier));                //this.TreeView1.Nodes.Clear();

                    childNode= new TreeNode(tempData.week + " " + tempData.year,"folder:" + tempData.week + " " + tempData.year);

                    UpdatedNode.ChildNodes.Add(childNode);

                    UpdatedNode = childNode;

                }

                //node to be added

                childNode = new TreeNode(tempData.filename, "file:" + tempData.filename);               

                //if the node already exists, remove it

                if (Exists)

                    UpdatedNode.ChildNodes.Remove(TreeView1.FindNode(UpdatedNode.ValuePath + "\\" + childNode.Value));

 

                //then add again as normal flow

                UpdatedNode.ChildNodes.Add(childNode);

                childNode.Select();

                childNode.ImageUrl = "~/metric15_2.gif";

                //always check the parent for null value

                if (childNode.Parent != null)

                    childNode.Parent.Expand();

                else

                    childNode.Expand();

            }

        }

    }

 }

 

 

Advertisements