Exemple #1
0
        public void HienThiTreeviewJobShare()
        {
            string UserID = (string)Session["UserID"].ToString();
            //string UserID = "27276";
            string      UserShare = DropDownUserName.SelectedValue;
            string      CongTy    = "LTY";
            RadTreeNode roott     = new RadTreeNode("Job Share");

            RadTreeView2.Nodes.Add(roott);
            DataTable dt = dalProjects.LayDanhSachTheoAuditor_TreeView(UserShare, UserID, CongTy);

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    string      jobID     = dr["jobid"].ToString();
                    string      jobName   = dr["jobname"].ToString();
                    RadTreeNode childNode = new RadTreeNode("");
                    childNode.Value = jobID;
                    childNode.Text  = jobName;
                    roott.Nodes.Add(childNode);
                    roott.ExpandChildNodes();
                }
            }
            RadTreeView2.ExpandAllNodes();
        }
 public void Initialize()
 {
     var categories = _categoryService.GetAll();
     var nodes = RecursivelySetTreeNode(categories, null);
     var rootNode = new RadTreeNode("Root", "-1");
     rootNode.Nodes.AddRange(nodes);
     rootNode.ExpandChildNodes();
     _categoryListingView.Categories.Nodes.Add(rootNode);
     _categoryListingView.Categories.ExpandAllNodes();
     _categoryListingView.Categories.DataBind();
 }
    protected void RefreshCommandsView()
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        ArrayList DBCommands = (ArrayList)State["DBCommands"];
        RadTreeNode DatabaseCommandRoot = CreateSpreadsheetRootNode();

        if (DBCommands == null)
            return;

        //re add the previous controls
        int command_index = 0;
        Hashtable prev_CommandEntry = null;
        foreach (Hashtable CommandEntry in DBCommands)
        {
            int sub_command_index = 0;
            RadTreeNode command_node = new RadTreeNode();
            command_node.CssClass = "RadTreeView";
            command_node.Category = "command";
            command_node.PostBack = false;

            string orig_command = CommandEntry["command"].ToString();
            string command = orig_command.ToLower();
            State["SelectedSqlCommand"] = command;

            Control CommandControl = null;
            string selected_table = null;
            if (CommandEntry["table"] != null && CommandEntry["table"].ToString().Length > 0)
            {
                State["SelectedDatabaseTable"] = selected_table = CommandEntry["table"].ToString();
                DataSources DS = new DataSources();
                State["DataSourceDatabaseTableFields"] = DS.GetDataSourceDatabaseTableFields(State);
                if (State["DataSourceDatabaseTableFields"] == null)
                {
                    ResetDatabaseConfig_Click(null, null);
                    Message.Text = "Internal Error:  All commands have been cleared.";
                    State["SpreadsheetError"] = null;
                    State["DBCommands"] = null;
                    State["SelectedDatabaseTable"] = null;
                    State["SelectedSqlCommand"] = null;
                    return ;
                }
            }

            if (command == "if")
            {
                CommandControl = LoadControl("Controls/IfDeviceFieldThenDoCommand.ascx");
            }
            else if(command.EndsWith("go to page"))
            {
                string selected_page = null;
                if (CommandEntry["page"] != null && CommandEntry["page"].ToString().Length > 0)
                {
                    State["SelectedGoToPage"] = selected_page = CommandEntry["page"].ToString();
                }
                CommandControl = LoadControl("Controls/GoToPage.ascx", selected_page);
                if (command.StartsWith("then "))
                {
                    command = command.Remove(0, 5);
                    ((RadComboBox)CommandControl.FindControl("command")).SelectedValue = command;
                    ((Label)CommandControl.FindControl("command_prefix")).Text = "Then ";
                }
                else if (command.StartsWith("else "))
                {
                    command = command.Remove(0, 5);
                    ((RadComboBox)CommandControl.FindControl("command")).SelectedValue = command;
                    ((Label)CommandControl.FindControl("command_prefix")).Text = "Else ";
                }
                else
                    ((RadComboBox)CommandControl.FindControl("command")).SelectedValue = command;

            }
            else
            {
                CommandControl = LoadControl("Controls/DatabaseCommand.ascx", selected_table);
                if (command.StartsWith("then "))
                {
                    command = command.Remove(0, 5);
                    ((RadComboBox)CommandControl.FindControl("command")).SelectedValue = command;
                    ((Label)CommandControl.FindControl("command_prefix")).Text = "Then ";
                }
                else if (command.StartsWith("else "))
                {
                    command = command.Remove(0, 5);
                    ((RadComboBox)CommandControl.FindControl("command")).SelectedValue = command;
                    ((Label)CommandControl.FindControl("command_prefix")).Text = "Else ";
                }
                else
                    ((RadComboBox)CommandControl.FindControl("command")).SelectedValue = command;

            }
            prev_CommandEntry = CommandEntry;

            command_node.Controls.Add(CommandControl);
            DatabaseCommandRoot.Nodes.Add(command_node);

            string field_control_type = null;

            if (command == "if")
            {
                if (CommandEntry["command_condition_device_field1"] != null && CommandEntry["command_condition_device_field1"].ToString().Length > 0)
                {
                    string command_condition_device_field1 = CommandEntry["command_condition_device_field1"].ToString();
                    ((HtmlInputText)CommandControl.FindControl("command_condition_device_field1")).Value = command_condition_device_field1;
                }
                else
                {
                    CommandEntry["command_condition_device_field1"] = ((HtmlInputText)CommandControl.FindControl("command_condition_device_field1")).Value;
                }
                if (CommandEntry["command_condition_operation"] != null && CommandEntry["command_condition_operation"].ToString().Length > 0)
                {
                    string command_condition_operation = CommandEntry["command_condition_operation"].ToString();
                    ((RadComboBox)CommandControl.FindControl("command_condition_operation")).SelectedValue = command_condition_operation;
                }
                else
                {
                    CommandEntry["command_condition_operation"] = ((RadComboBox)CommandControl.FindControl("command_condition_operation")).SelectedValue;
                }
                if (CommandEntry["command_condition_device_field2"] != null && CommandEntry["command_condition_device_field2"].ToString().Length > 0)
                {
                    string command_condition_device_field2 = CommandEntry["command_condition_device_field2"].ToString();
                    HtmlInputText command_condition_device_field2_input = ((HtmlInputText)CommandControl.FindControl("command_condition_device_field2"));
                    command_condition_device_field2_input.Value = command_condition_device_field2;
                }
                else
                {
                    CommandEntry["command_condition_device_field2"] = ((HtmlInputText)CommandControl.FindControl("command_condition_device_field2")).Value;
                }
                continue;
            }

            else if (command == "insert into")
            {
                ((ImageButton)CommandControl.FindControl("add_condition")).Visible = false;
                ((ImageButton)CommandControl.FindControl("add_order_by")).Visible = false;
                field_control_type = "from_phone_to_database";
            }
            else if (command == "update")
            {
                ((ImageButton)CommandControl.FindControl("add_order_by")).Visible = false;
                field_control_type = "from_phone_to_database";
            }
            else if (command == "select from")
            {
                field_control_type = "from_database_to_phone";
            }
            else if (command == "delete from")
            {
                ((ImageButton)CommandControl.FindControl("add_field")).Visible = false;
                ((ImageButton)CommandControl.FindControl("add_order_by")).Visible = false;
            }

             ArrayList DBFields = (ArrayList)CommandEntry["database_fields"];
            if (DBFields != null && field_control_type != null)
            {
                foreach (Hashtable FieldEntry in DBFields)
                {
                    RadTreeNode field_node = new RadTreeNode();
                    field_node.CssClass = "RadTreeView";
                    field_node.Category = "field";
                    field_node.PostBack = false;
                    State["SelectedDatabaseTable"] = selected_table;
                    string control_file = (field_control_type == "from_database_to_phone") ? "DatabaseToDeviceField.ascx" : "DeviceToDatabaseField.ascx";
                    string selected_database_field = null;
                    if (FieldEntry["database_field"] != null && FieldEntry["database_field"].ToString().Length > 0)
                    {
                        selected_database_field = FieldEntry["database_field"].ToString();
                    }
                    else
                    {
                        ArrayList DataSourceDatabaseTableFields = (ArrayList)State["DataSourceDatabaseTableFields"];
                        selected_database_field = DataSourceDatabaseTableFields[0].ToString();
                    }

                    Control FieldControl = LoadControl("Controls/" + control_file, selected_database_field);
                    if (State["SpreadsheetError"] != null)
                    {
                        ResetDatabaseConfig_Click(null, null);
                        Message.Text = State["SpreadsheetError"].ToString();
                        State["SpreadsheetError"] = null;
                        State["DBCommands"] = null;
                        State["SelectedDatabaseTable"] = null;
                        State["SelectedSqlCommand"] = null;
                        return;
                    }
                    field_node.Controls.Add(FieldControl);
                    command_node.Nodes.Add(field_node);

                    if (FieldEntry["device_field"] != null && FieldEntry["device_field"].ToString().Length > 0)
                    {
                        string phone_field = FieldEntry["device_field"].ToString();
                        HtmlInputText phone_field_input = (HtmlInputText)FieldControl.FindControl("device_field");
                        phone_field_input.Value = phone_field;
                    }
                    sub_command_index++;
                }
            }
            ArrayList DBWhere = (ArrayList)CommandEntry["conditions"];
            if (DBWhere != null)
            {
                int i_condition = 0;
                // Hashtable uniqueConditionIDs = new Hashtable();
                foreach (Hashtable ConditionEntry in DBWhere)
                {
                    if (i_condition == 0)
                        State["IsFirstCommandCondition"] = true;
                    else
                        State["IsFirstCommandCondition"] = false;

                    RadTreeNode where_node = new RadTreeNode();
                    where_node.CssClass = "RadTreeView";
                    where_node.Category = "condition";
                    where_node.PostBack = false;
                    State["SelectedDatabaseTable"] = selected_table;
                    string selected_condition_1st_field = null;
                    if (ConditionEntry["condition_1st_field"] != null && ConditionEntry["condition_1st_field"].ToString().Length > 0)
                    {
                        selected_condition_1st_field = ConditionEntry["condition_1st_field"].ToString();
                    }
                    else
                    {
                        ArrayList DataSourceDatabaseTableFields = (ArrayList)State["DataSourceDatabaseTableFields"];
                        selected_condition_1st_field = DataSourceDatabaseTableFields[0].ToString();
                    }
                    Control WhereControl = LoadControl("Controls/SpreadsheetWhere.ascx", selected_condition_1st_field);

                    if (State["SpreadsheetError"] != null)
                    {
                        ResetDatabaseConfig_Click(null, null);
                        Message.Text = State["SpreadsheetError"].ToString();
                        State["SpreadsheetError"] = null;
                        State["DBCommands"] = null;
                        State["SelectedDatabaseTable"] = null;
                        State["SelectedSqlCommand"] = null;
                        return;
                    }

                    where_node.Controls.Add(WhereControl);

                    command_node.Nodes.Add(where_node);

                    if (ConditionEntry["condition_operation"] != null && ConditionEntry["condition_operation"].ToString().Length > 0)
                    {
                        string condition_operation = ConditionEntry["condition_operation"].ToString();
                        ((RadComboBox)WhereControl.FindControl("condition_operation")).SelectedValue = condition_operation;
                    }
                    else
                    {
                        ConditionEntry["condition_operation"] = ((RadComboBox)WhereControl.FindControl("condition_operation")).SelectedValue;
                    }
                   if (ConditionEntry["field_operation"] != null && ConditionEntry["field_operation"].ToString().Length > 0)
                    {
                        string field_operation = ConditionEntry["field_operation"].ToString();
                        ((RadComboBox)WhereControl.FindControl("field_operation")).SelectedValue = field_operation;
                    }
                    else
                    {
                        ConditionEntry["field_operation"] = ((RadComboBox)WhereControl.FindControl("field_operation")).SelectedValue;
                    }
                    if (ConditionEntry["condition_2nd_field"] != null && ConditionEntry["condition_2nd_field"].ToString().Length > 0)
                    {
                        string condition_2nd_field = ConditionEntry["condition_2nd_field"].ToString();
                        HtmlInputText condition_2nd_field_input = (HtmlInputText)WhereControl.FindControl("condition_2nd_field");
                        condition_2nd_field_input.Value = condition_2nd_field;
                    }
                    i_condition++;
                    sub_command_index++;
                }
            }
            Hashtable DBOrderBy = (Hashtable)CommandEntry["order_by"];
            if (DBOrderBy != null)
            {
                RadTreeNode orderBy_node = new RadTreeNode();
                orderBy_node.CssClass = "RadTreeView";
                orderBy_node.Category = "order_by";
                orderBy_node.PostBack = false;
                State["SelectedDatabaseTable"] = selected_table;
                string selected_sort_field = null;
                if (DBOrderBy["sort_field"] != null && DBOrderBy["sort_field"].ToString().Length > 0)
                {
                    selected_sort_field = DBOrderBy["sort_field"].ToString();
                }
                else
                {
                    ArrayList DataSourceDatabaseTableFields = (ArrayList)State["DataSourceDatabaseTableFields"];
                    selected_sort_field = DataSourceDatabaseTableFields[0].ToString();
                }

                Control OrderByControl = LoadControl("Controls/DatabaseOrderBy.ascx", selected_sort_field);
                if (State["SpreadsheetError"] != null)
                {
                    ResetDatabaseConfig_Click(null, null);
                    Message.Text = State["SpreadsheetError"].ToString();
                    State["SpreadsheetError"] = null;
                    State["DBCommands"] = null;
                    State["SelectedDatabaseTable"] = null;
                    State["SelectedSqlCommand"] = null;
                    return;
                }

                orderBy_node.Controls.Add(OrderByControl);
                command_node.Nodes.Add(orderBy_node);

                if (DBOrderBy["sort_direction"] != null && DBOrderBy["sort_direction"].ToString().Length > 0)
                {
                    string sort_direction = DBOrderBy["sort_direction"].ToString();
                    ((RadComboBox)OrderByControl.FindControl("sort_direction")).SelectedValue = sort_direction;
                }
                sub_command_index++;
            }

            command_node.ExpandChildNodes();
            command_index++;
        }
        SpreadsheetCommandsView.ExpandAllNodes();
    }
Exemple #4
0
    public void AjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        string[]    args    = e.Argument.Replace("\r\n", "\n").Split('\n');
        RadTreeView srcTree = null;
        RadTreeView dstTree = null;

        if (TreeResources.ClientID.Equals(args[0]))
        {
            srcTree = TreeResources;
        }
        else if (TreeResources.ClientID.Equals(args[0]))
        {
            srcTree = TreeResources;
        }

        if (TreeResources.ClientID.Equals(args[1]))
        {
            dstTree = TreeResources;
        }
        else if (TreeResources.ClientID.Equals(args[1]))
        {
            dstTree = TreeResources;
        }

        RadTreeNode sourceNode = srcTree.FindNodeByText(args[2]);
        RadTreeNode destNode   = dstTree.FindNodeByText(args[3]);

        //if (sourceNode.Parent == null)
        //{
        //    RadAjaxManager1.Alert("گره اصلی قابل حذف نیست");
        //    return;
        //}
        RadTreeNode tempNode = destNode;

        while (tempNode != null)
        {
            if (!tempNode.Equals(sourceNode))
            {
                tempNode = tempNode.ParentNode;
            }
            else
            {
                break;
            }
        }
        if (tempNode != null)
        {
            //RadAjaxManager1.Alert("نمیتوان یک گره را به فرزندانش منتقل کرد");
            return;
        }

        BOLResources ResourcesBOl = new BOLResources();

        ResourcesBOl.Code       = Convert.ToInt32(sourceNode.Value);
        ResourcesBOl.MasterCode = Convert.ToInt32(destNode.Value);
        ResourcesBOl.Name       = sourceNode.Text;
        ResourcesBOl.SaveChanges(false);

        RadTreeNode newNode = new RadTreeNode(sourceNode.Text, sourceNode.Value);

        AddChilds(newNode, sourceNode);
        destNode.Nodes.Add(newNode);
        destNode.ExpandChildNodes();
        if (!sourceNode.Equals(srcTree.Nodes[0]))
        {
            sourceNode.Remove();
        }
    }
    protected void RefreshCommandsView()
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        ArrayList DBCommands = (ArrayList)State["DBCommands"];
        if (DBCommands == null)
            return;

        RadTreeNode DatabaseCommandRoot = CreateDatabaseRootNode(DatabaseEvents.SelectedValue);

        //re add the previous controls
        int command_index = 0;
        Hashtable prev_CommandEntry = null;
        foreach (Hashtable CommandEntry in DBCommands)
        {
            int sub_command_index = 0;
            RadTreeNode command_node = new RadTreeNode();
            command_node.CssClass = "RadTreeView";
            command_node.Category = "command";
            command_node.PostBack = false;

            string orig_command = CommandEntry["command"].ToString();
            string command = orig_command.ToLower();
             State["SelectedSqlCommand"] = command;

            Control CommandControl = null;
            if (command == "if")
            {
                CommandControl = LoadControl("Controls/IfDeviceFieldThenDoCommand.ascx");
            }
            else
            {
                CommandControl = LoadControl("Controls/DatabaseCommand.ascx");
                if (command.StartsWith("then "))
                {
                    command = command.Remove(0, 5);
                    ((RadComboBox)CommandControl.FindControl("command")).SelectedValue = command;
                    ((Label)CommandControl.FindControl("command_prefix")).Text = "Then ";
                }
                else if (command.StartsWith("else "))
                {
                    command = command.Remove(0, 5);
                    ((RadComboBox)CommandControl.FindControl("command")).SelectedValue = command;
                    ((Label)CommandControl.FindControl("command_prefix")).Text = "Else ";
                }
                else
                    ((RadComboBox)CommandControl.FindControl("command")).SelectedValue = command;

            }
            prev_CommandEntry = CommandEntry;

            command_node.Controls.Add(CommandControl);
            DatabaseCommandRoot.Nodes.Add(command_node);

            string field_control_type = null;

            if (command == "if")
            {
                if (CommandEntry["command_condition_device_field1"] != null && CommandEntry["command_condition_device_field1"].ToString().Length > 0)
                {
                    string command_condition_device_field1 = CommandEntry["command_condition_device_field1"].ToString();
                    ((RadComboBox)CommandControl.FindControl("command_condition_device_field1")).SelectedValue = command_condition_device_field1;
                }
                else
                {
                    CommandEntry["command_condition_device_field1"] = ((RadComboBox)CommandControl.FindControl("command_condition_device_field1")).SelectedValue;
                }
                if (CommandEntry["command_condition_operation"] != null && CommandEntry["command_condition_operation"].ToString().Length > 0)
                {
                    string command_condition_operation = CommandEntry["command_condition_operation"].ToString();
                    ((RadComboBox)CommandControl.FindControl("command_condition_operation")).SelectedValue = command_condition_operation;
                }
                else
                {
                    CommandEntry["command_condition_operation"] = ((RadComboBox)CommandControl.FindControl("command_condition_operation")).SelectedValue;
                }
                if (CommandEntry["command_condition_device_field2"] != null && CommandEntry["command_condition_device_field2"].ToString().Length > 0)
                {
                    string command_condition_device_field2 = CommandEntry["command_condition_device_field2"].ToString();
                    RadComboBox command_condition_device_field2_combo = ((RadComboBox)CommandControl.FindControl("command_condition_device_field2"));
                    command_condition_device_field2_combo.SelectedIndex = -1;
                    command_condition_device_field2_combo.Text = command_condition_device_field2;
                }
                else
                {
                    CommandEntry["command_condition_device_field2"] = ((RadComboBox)CommandControl.FindControl("command_condition_device_field2")).SelectedValue;
                }
                continue;
            }

            else if (command == "insert into")
            {
                ((ImageButton)CommandControl.FindControl("add_condition")).Visible = false;
                ((ImageButton)CommandControl.FindControl("add_order_by")).Visible = false;
                field_control_type = "from_phone_to_database";
            }
            else if (command == "update")
            {
                ((ImageButton)CommandControl.FindControl("add_order_by")).Visible = false;
                field_control_type = "from_phone_to_database";
            }
            else if (command == "select from")
            {
                field_control_type = "from_database_to_phone";
            }
            else if (command == "delete from")
            {
                ((ImageButton)CommandControl.FindControl("add_field")).Visible = false;
                ((ImageButton)CommandControl.FindControl("add_order_by")).Visible = false;
            }

            string table = CommandEntry["table"].ToString();
            //check if database_field is in combobox
            RadComboBox table_select = (RadComboBox)CommandControl.FindControl("table");
            ArrayList DBFields = null;
            if (table_select.Items.FindItemByValue(table) != null)
            {
                table_select.SelectedValue = table;
                DBFields = (ArrayList)CommandEntry["database_fields"];
            }
            else
            {
                table_select.Items.Insert(0, new RadComboBoxItem("Select ->", "no_value"));
                table_select.SelectedIndex = 0;
                GoogleDocsConfigMessage.Text = "The saved table name is no longer valid. All fields have been cleared.";
                CommandEntry["conditions"] = null;
                CommandEntry["order_by"] = null;
            }
             if (DBFields != null && field_control_type != null)
            {
                foreach (Hashtable FieldEntry in DBFields)
                {
                    RadTreeNode field_node = new RadTreeNode();
                    field_node.CssClass = "RadTreeView";
                    field_node.Category = "field";
                    field_node.PostBack = false;
                     State["SelectedDatabaseTable"] = table;
                    string control_file = (field_control_type == "from_database_to_phone") ? "DatabaseToDeviceField.ascx" : "DeviceToDatabaseField.ascx";
                    Control FieldControl = LoadControl("Controls/" +control_file);
                    if ( State["SpreadsheetError"] != null)
                    {
                        GoogleDocsConfigMessage.Text =  State["SpreadsheetError"].ToString();
                        return;
                    }
                    field_node.Controls.Add(FieldControl);
                    command_node.Nodes.Add(field_node);

                    if (FieldEntry["database_field"] != null && FieldEntry["database_field"].ToString().Length > 0)
                    {
                        string database_field = FieldEntry["database_field"].ToString();
                        //check if database_field is in combobox
                        RadComboBox database_field_select = (RadComboBox)FieldControl.FindControl("database_field");
                        if (database_field_select.Items.FindItemByValue(database_field) != null)
                            database_field_select.SelectedValue = database_field;
                        else //add select item
                        {
                            database_field_select.Items.Insert(0,new RadComboBoxItem("Select ->","no_value"));
                            database_field_select.SelectedIndex = 0;
                        }
                    }
                    else
                    {
                        FieldEntry["database_field"] = ((RadComboBox)FieldControl.FindControl("database_field")).SelectedValue;
                    }
                    if (FieldEntry["device_field"] != null && FieldEntry["device_field"].ToString().Length > 0)
                    {
                        string phone_field = FieldEntry["device_field"].ToString();
                        RadComboBox phone_field_combo = (RadComboBox)FieldControl.FindControl("device_field");
                        phone_field_combo.SelectedIndex = -1;
                        phone_field_combo.Text = phone_field;
                    }
                    else
                    {
                        string phone_field_text = ((RadComboBox)FieldControl.FindControl("device_field")).Text;
                        if (phone_field_text.Length > 0)
                            FieldEntry["device_field"] = phone_field_text;
                        else
                            FieldEntry["device_field"] = ((RadComboBox)FieldControl.FindControl("device_field")).SelectedValue;
                    }
                    sub_command_index++;
                }
            }
            ArrayList DBWhere = (ArrayList)CommandEntry["conditions"];
            if (DBWhere != null)
            {
                int i_condition = 0;
                // Hashtable uniqueConditionIDs = new Hashtable();
                foreach (Hashtable ConditionEntry in DBWhere)
                {
                    if (i_condition == 0)
                         State["IsFirstCommandCondition"] = true;
                    else
                         State["IsFirstCommandCondition"] = false;

                    RadTreeNode where_node = new RadTreeNode();
                    where_node.CssClass = "RadTreeView";
                    where_node.Category = "condition";
                    where_node.PostBack = false;
                     State["SelectedDatabaseTable"] = table;
                    Control WhereControl = LoadControl("Controls/DatabaseWhere.ascx");
                    if ( State["SpreadsheetError"] != null)
                    {
                        GoogleDocsConfigMessage.Text =  State["SpreadsheetError"].ToString();
                        return;
                    }

                    where_node.Controls.Add(WhereControl);

                    command_node.Nodes.Add(where_node);

                    if (ConditionEntry["condition_operation"] != null && ConditionEntry["condition_operation"].ToString().Length > 0)
                    {
                        string condition_operation = ConditionEntry["condition_operation"].ToString();
                        ((RadComboBox)WhereControl.FindControl("condition_operation")).SelectedValue = condition_operation;
                    }
                    else
                    {
                        ConditionEntry["condition_operation"] = ((RadComboBox)WhereControl.FindControl("condition_operation")).SelectedValue;
                    }
                    if (ConditionEntry["condition_1st_field"] != null && ConditionEntry["condition_1st_field"].ToString().Length > 0)
                    {
                        string condition_1st_field = ConditionEntry["condition_1st_field"].ToString();
                        //check if database field is in combobox
                        RadComboBox condition_1st_field_select = (RadComboBox)WhereControl.FindControl("condition_1st_field");
                        if (condition_1st_field_select.Items.FindItemByValue(condition_1st_field) != null)
                            condition_1st_field_select.SelectedValue = condition_1st_field;
                        else //add select item
                        {
                            condition_1st_field_select.Items.Insert(0,new RadComboBoxItem("Select ->","no_value"));
                            condition_1st_field_select.SelectedIndex = 0;
                        }
                    }
                    else
                    {
                        ConditionEntry["condition_1st_field"] = ((RadComboBox)WhereControl.FindControl("condition_1st_field")).SelectedValue;
                    }
                    if (ConditionEntry["field_operation"] != null && ConditionEntry["field_operation"].ToString().Length > 0)
                    {
                        string field_operation = ConditionEntry["field_operation"].ToString();
                        ((RadComboBox)WhereControl.FindControl("field_operation")).SelectedValue = field_operation;
                    }
                    else
                    {
                        ConditionEntry["field_operation"] = ((RadComboBox)WhereControl.FindControl("field_operation")).SelectedValue;
                    }
                    if (ConditionEntry["condition_2nd_field"] != null && ConditionEntry["condition_2nd_field"].ToString().Length > 0)
                    {
                        string condition_2nd_field = ConditionEntry["condition_2nd_field"].ToString();
                        RadComboBox condition_2nd_field_combo = (RadComboBox)WhereControl.FindControl("condition_2nd_field");
                        condition_2nd_field_combo.SelectedIndex = -1;
                        condition_2nd_field_combo.Text = condition_2nd_field;
                    }
                    else
                    {
                        ConditionEntry["condition_2nd_field"] = ((RadComboBox)WhereControl.FindControl("condition_2nd_field")).Text;
                    }
                    i_condition++;
                    sub_command_index++;
                }
            }
            Hashtable DBOrderBy = (Hashtable)CommandEntry["order_by"];
            if (DBOrderBy != null)
            {
                RadTreeNode orderBy_node = new RadTreeNode();
                orderBy_node.CssClass = "RadTreeView";
                orderBy_node.Category = "order_by";
                orderBy_node.PostBack = false;
                 State["SelectedDatabaseTable"] = table;
                Control OrderByControl = LoadControl("Controls/DatabaseOrderBy.ascx");
                if ( State["SpreadsheetError"] != null)
                {
                    GoogleDocsConfigMessage.Text =  State["SpreadsheetError"].ToString();
                    return;
                }

                orderBy_node.Controls.Add(OrderByControl);
                command_node.Nodes.Add(orderBy_node);

                if (DBOrderBy["sort_field"] != null && DBOrderBy["sort_field"].ToString().Length > 0)
                {
                    string sort_field = DBOrderBy["sort_field"].ToString();
                    //check if database_field is in combobox
                    RadComboBox sort_field_select = (RadComboBox)OrderByControl.FindControl("sort_field");
                    if (sort_field_select.Items.FindItemByValue(sort_field) != null)
                        sort_field_select.SelectedValue = sort_field;
                    else //add select item
                    {
                        sort_field_select.Items.Insert(0, new RadComboBoxItem("Select ->", "no_value"));
                        sort_field_select.SelectedIndex = 0;
                    }
                }
                else
                {
                    DBOrderBy["sort_field"] = ((RadComboBox)OrderByControl.FindControl("sort_field")).SelectedValue;
                }
                if (DBOrderBy["sort_direction"] != null && DBOrderBy["sort_direction"].ToString().Length > 0)
                {
                    string sort_direction = DBOrderBy["sort_direction"].ToString();
                    ((RadComboBox)OrderByControl.FindControl("sort_direction")).SelectedValue = sort_direction;
                }
                else
                {
                    DBOrderBy["sort_direction"] = ((RadComboBox)OrderByControl.FindControl("sort_direction")).SelectedValue;
                }
                sub_command_index++;
            }

            command_node.ExpandChildNodes();
            command_index++;
        }
        if ( State["ManageDataType"].ToString() == "database")
            DatabaseCommandsView.ExpandAllNodes();

        else
            SpreadsheetCommandsView.ExpandAllNodes();
    }
    protected void InitWebServiceNodes(XmlDocument doc, string event_field, RadTreeNode url_node,
        RadTreeNode WebServiceResponseRoot, XmlNode phone_data_requests)
    {
        string url = url_node.Text;
        url_node.ExpandParentNodes();
        url_node.CollapseChildNodes();
        Hashtable WebServiceMethodInputs = new Hashtable();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        State["WebServiceMethodInputs"] = WebServiceMethodInputs;
        RadTreeNode out_url = new RadTreeNode(url);
        out_url.CssClass = "RadTreeView";
        out_url.ImageUrl = "~/images/dialog.gif";
        WebServiceResponseRoot.Nodes.Add(out_url);

        Util util = new Util();

        if (!url.EndsWith("?WSDL"))
            url += "?WSDL";
        string xml = util.GetWebPage(url);
        if (xml == null)
        {
            SaveRequestMessage.Text = "Accessing " + url + " resulted in an error";
            return;
        }
        XmlDocument WebDoc = new XmlDocument();
        WebDoc.LoadXml(xml);
        XmlNamespaceManager nsmgr = new XmlNamespaceManager(WebDoc.NameTable);
        nsmgr.AddNamespace("s", "http://www.w3.org/2001/XMLSchema");

        XmlNodeList web_methods = WebDoc.SelectNodes("//s:schema/s:element", nsmgr);
        if (web_methods.Count == 0)
        {
            nsmgr.AddNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
            web_methods = WebDoc.SelectNodes("//wsdl:operation", nsmgr);
            if (web_methods.Count == 0)
            {
                SaveRequestMessage.Text = "Could not find any methods with URL: " + url;
                return;
            }
        }
        Hashtable used_names = new Hashtable();
        foreach (XmlNode web_method in web_methods)
        {
            //throw out certain methods with <s:any />
            if (web_method.InnerXml.Contains("s:any"))
                continue;
            string web_method_name = web_method.Attributes["name"].Value;
            if (used_names.ContainsKey(web_method_name))
                continue;
            used_names[web_method_name] = true;
            ArrayList MethodInputs = new ArrayList();
            string service_url = out_url.Text;
            if (out_url.Text.ToLower().EndsWith("?wsdl"))
                service_url = service_url.Remove(url.Length - 5);
            WebServiceMethodInputs[service_url + "/" + web_method_name] = MethodInputs;
            RadTreeNode in_method_node = new RadTreeNode(web_method_name);
            in_method_node.CssClass = "RadTreeView";
            in_method_node.ImageUrl = "~/images/forward_nav.gif";
            url_node.Nodes.Add(in_method_node);

            //response web methods
            XmlNode mapped_node = phone_data_requests.SelectSingleNode("//event_field[.='" + event_field + "']");
            RadTreeNode out_method_node = null;
            if (mapped_node != null &&  State["WebServiceTestDoc"] != null &&  State["WebServiceResponseTreeViewNodeText"] != null &&
                  State["WebServiceResponseTreeViewNodeText"].ToString() == web_method_name)
            {
                //make sure we are in the right event
                XmlNode method_node = mapped_node.ParentNode.SelectSingleNode("method");
                if (method_node != null && method_node.InnerText == web_method_name)
                {
                    XmlDocument TestDoc = (XmlDocument) State["WebServiceTestDoc"];
                    out_method_node = new RadTreeNode(web_method_name);
                     State["WebServiceResponseTreeViewMethodText"] = web_method_name;
                    out_method_node.CssClass = "RadTreeView";
                    out_method_node.ImageUrl = "~/images/backward_nav.gif";
                    out_method_node.Category = "method";
                    out_method_node.Value = service_url + ";" + web_method_name + ";";
                    out_url.Nodes.Add(out_method_node);
                    out_method_node.Value.Remove(out_method_node.Value.Length - 1, 1);
                    WebServiceResponseTreeView.ExpandAllNodes();

                    XmlToTreeViewNode(TestDoc.FirstChild.NextSibling, out_method_node, web_method_name);

                    out_method_node.ExpandParentNodes();

                    Session.Remove("WebServiceTestDoc");
                }
            }
            else if (mapped_node != null)
            {
                XmlNode web_service_node = mapped_node.ParentNode.SelectSingleNode("web_service[.='" + service_url + "']");
                XmlNode method_node = mapped_node.ParentNode.SelectSingleNode("method[.='" + web_method_name + "']");
                if (web_service_node != null && method_node != null)
                {
                    in_method_node.BackColor = Color.LightCoral;

                    out_method_node = new RadTreeNode(web_method_name);
                    out_method_node.CssClass = "RadTreeView";
                    out_method_node.ImageUrl = "~/images/backward_nav.gif";
                    out_method_node.Category = "method";
                    out_method_node.Value = service_url + ";" + web_method_name + ";";
                    out_url.Nodes.Add(out_method_node);
                    out_method_node.Value.Remove(out_method_node.Value.Length - 1, 1);
                    WebServiceResponseTreeView.ExpandAllNodes();
                }
            }

            XmlNodeList parms = web_method.SelectNodes("s:complexType/s:sequence/s:element", nsmgr);
            foreach (XmlNode parm in parms)
            {
                string parm_name = parm.Attributes["name"].Value;
                MethodInputs.Add(parm_name);
                if (out_method_node != null)
                    out_method_node.Value += parm_name + ",";
                RadTreeNode parm_node = new RadTreeNode(parm_name);
                parm_node.CssClass = "RadTreeView";
                parm_node.ImageUrl = "~/images/dot.gif";
                parm_node.Category = "input";
                parm_node.BackColor = Color.FromArgb(250, 252, 156);
                in_method_node.Nodes.Add(parm_node);

                if (mapped_node != null)
                {
                    XmlNode web_service_node = mapped_node.ParentNode.SelectSingleNode("web_service[.='" + service_url + "']");
                    XmlNode method_node = mapped_node.ParentNode.SelectSingleNode("method[.='" + web_method_name + "']");
                    if (web_service_node != null && method_node != null)
                    {
                        XmlNode web_service_method_input_node = mapped_node.ParentNode.SelectSingleNode("input_mapping/web_service_method_input[.='" + parm_name + "']");
                        if (web_service_method_input_node != null)
                        {
                            XmlNode input_field_node = web_service_method_input_node.ParentNode.SelectSingleNode("input_field");
                            if (input_field_node != null)
                            {
                                string request_name = input_field_node.InnerText;
                                XmlNode field_node = doc.SelectSingleNode("//id[.='" + request_name + "']");
                                RadTreeNode request_node = null;
                                if (field_node == null)

                                    request_node = util.CreateFieldNode(parm_node, request_name, "");
                                else
                                    request_node = util.CreateFieldNode(parm_node, request_name, field_node.ParentNode.Name);

                                request_node.Text = request_name;
                                request_node.Category = "request";
                                request_node.BackColor = Color.FromArgb(153, 255, 185); //LIGHT GREEN
                            }
                        }
                    }
                }
            }
            RadTreeNode save_method_node = new RadTreeNode("Save calling this method with 0 or more inputs mapped");
            save_method_node.CssClass = "RadTreeView";
            save_method_node.ImageUrl = "~/images/save.gif";
            save_method_node.Category = "save";
            in_method_node.Nodes.Add(save_method_node);

            RadTreeNode undo_method_inputs_node = new RadTreeNode("Undo mapping of device fields to this method");
            undo_method_inputs_node.CssClass = "RadTreeView";
            undo_method_inputs_node.ImageUrl = "~/images/cancel.png";
            undo_method_inputs_node.Category = "delete";
            in_method_node.Nodes.Add(undo_method_inputs_node);
            in_method_node.ExpandChildNodes();
        }
    }
Exemple #7
0
        public void HienThiTreeview()
        {
            string UserID = (string)Session["UserID"].ToString();
            //string UserID = "27276";
            string      CongTy   = "LTY";
            RadTreeNode roottree = new RadTreeNode("System");

            RadTreeView1.Nodes.Add(roottree);

            DataTable dtSystem = dalSystem.QryProjectTheoUserID(UserID, CongTy);

            if (dtSystem.Rows.Count > 0)
            {
                foreach (DataRow row in dtSystem.Rows)
                {
                    string      SysID   = row["jsysid"].ToString();
                    string      SysName = row["sysname"].ToString();
                    RadTreeNode nootcha = new RadTreeNode("");
                    nootcha.Text  = SysName;
                    nootcha.Value = SysID;
                    roottree.Nodes.Add(nootcha);
                    roottree.ExpandChildNodes();
                    DataTable dtProjectm = dalProjectm.QryProjectTheoUserID1(UserID, CongTy, SysID);

                    if (dtProjectm.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtProjectm.Rows)
                        {
                            string      SystemID    = dr["jsysid"].ToString();
                            string      subSystemID = dr["jsubid"].ToString();
                            string      subName     = dr["jsubname"].ToString();
                            RadTreeNode parentNode  = new RadTreeNode("Sub System");
                            parentNode.Text    = subName;
                            parentNode.ToolTip = subSystemID;
                            parentNode.Value   = SystemID.ToString();
                            nootcha.Nodes.Add(parentNode);
                            nootcha.ExpandChildNodes();
                            DataTable dtProjects = dalProjects.HienThiDanhSachTheoHeThong(UserID, CongTy, SystemID, subSystemID);
                            if (dtProjects.Rows.Count > 0)
                            {
                                foreach (DataRow drs in dtProjects.Rows)
                                {
                                    string      systemID  = drs["jsysid"].ToString();
                                    string      subSystem = drs["jsubid"].ToString();
                                    string      jobID     = drs["jobid"].ToString();
                                    string      jobName   = drs["jobname"].ToString();
                                    RadTreeNode childNode = new RadTreeNode("");
                                    childNode.Value   = jobID;
                                    childNode.ToolTip = subSystem;
                                    childNode.Target  = systemID.ToString();
                                    childNode.Text    = jobName;
                                    parentNode.Nodes.Add(childNode);
                                    parentNode.ExpandChildNodes();
                                }
                            }
                        }
                    }
                }
            }
            RadTreeView1.ExpandAllNodes();
        }
    protected void RefreshCommandsView(int command_index)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        ArrayList DBCommands = (ArrayList)State["DBCommands"];
        RadTreeNode DatabaseCommandRoot = CreateSpreadsheetRootNode();

        if (DBCommands == null)
            return;

        //re add the previous controls
        Hashtable prev_CommandEntry = null;
        Hashtable CommandEntry = (Hashtable)DBCommands[command_index];
        State["TestCommandEntry"] = CommandEntry;
        int sub_command_index = 0;
        RadTreeNode command_node = new RadTreeNode();
        command_node.CssClass = "RadTreeView";
        command_node.Category = "command";
        command_node.PostBack = false;

        string orig_command = CommandEntry["command"].ToString();
        string command = orig_command.ToLower();
        State["SelectedSqlCommand"] = command;

        Control CommandControl = null;
        string selected_table = null;
        if (CommandEntry["table"] != null && CommandEntry["table"].ToString().Length > 0)
        {
            State["SelectedDatabaseTable"] = selected_table = CommandEntry["table"].ToString();
        }

        CommandControl = LoadControl("../Controls/DatabaseCommandTest.ascx", selected_table);
        if (command.StartsWith("then "))
        {
            command = command.Remove(0, 5);
            ((HtmlInputText)CommandControl.FindControl("command")).Value = command;
            ((Label)CommandControl.FindControl("command_prefix")).Text = "Then ";
        }
        else if (command.StartsWith("else "))
        {
            command = command.Remove(0, 5);
            ((HtmlInputText)CommandControl.FindControl("command")).Value = command;
            ((Label)CommandControl.FindControl("command_prefix")).Text = "Else ";
        }
        else
            ((HtmlInputText)CommandControl.FindControl("command")).Value = command;

        prev_CommandEntry = CommandEntry;

        command_node.Controls.Add(CommandControl);
        DatabaseCommandRoot.Nodes.Add(command_node);

        string field_control_type = null;

        if (command == "insert into")
        {
            field_control_type = "from_phone_to_database";
        }
        else if (command == "update")
        {
             field_control_type = "from_phone_to_database";
        }
        else if (command == "select from")
        {
            field_control_type = "from_database_to_phone";
        }

        ArrayList DBFields = (ArrayList)CommandEntry["database_fields"];
        if (DBFields != null && field_control_type != null)
        {
            Hashtable TestInputValueMap = new Hashtable();
            State["TestInputValueMap"] = TestInputValueMap;
            foreach (Hashtable FieldEntry in DBFields)
            {
                RadTreeNode field_node = new RadTreeNode();
                field_node.CssClass = "RadTreeView";
                field_node.Category = "field";
                field_node.PostBack = false;
                State["SelectedDatabaseTable"] = selected_table;
                string control_file = (field_control_type == "from_database_to_phone") ? "DatabaseToDeviceFieldTest.ascx" : "DeviceToDatabaseFieldTest.ascx";
                string selected_database_field = "";
                if (FieldEntry["database_field"] != null && FieldEntry["database_field"].ToString().Length > 0)
                {
                    selected_database_field = FieldEntry["database_field"].ToString();
                }

                Control FieldControl = LoadControl("../Controls/" + control_file, selected_database_field);

                if (State["SpreadsheetError"] != null)
                {
                    Message.Text = State["SpreadsheetError"].ToString();
                    State["SpreadsheetError"] = null;
                    State["DBCommands"] = null;
                    State["SelectedDatabaseTable"] = null;
                    State["SelectedSqlCommand"] = null;
                    return;
                }
                field_node.Controls.Add(FieldControl);
                command_node.Nodes.Add(field_node);

                if (field_control_type == "from_database_to_phone")
                {
                    if (FieldEntry["device_field"] != null && FieldEntry["device_field"].ToString().Length > 0)
                    {
                        string device_field = FieldEntry["device_field"].ToString();
                        HtmlInputText device_field_input = (HtmlInputText)FieldControl.FindControl("device_field");
                        device_field_input.Value = device_field;
                    }
                }
                else
                {
                    TestInputValueMap[FieldEntry["database_field"].ToString()] = (HtmlInputText)FieldControl.FindControl("device_field");
                }

                sub_command_index++;
            }
        }
        ArrayList DBWhere = (ArrayList)CommandEntry["conditions"];
        if (DBWhere != null)
        {
            int i_condition = 0;
            // Hashtable uniqueConditionIDs = new Hashtable();
            Hashtable TestWhereValueMap = new Hashtable();
            State["TestWhereValueMap"] = TestWhereValueMap;

            foreach (Hashtable ConditionEntry in DBWhere)
            {
                if (i_condition == 0)
                    State["IsFirstCommandCondition"] = true;
                else
                    State["IsFirstCommandCondition"] = false;

                RadTreeNode where_node = new RadTreeNode();
                where_node.CssClass = "RadTreeView";
                where_node.Category = "condition";
                where_node.PostBack = false;
                State["SelectedDatabaseTable"] = selected_table;
                string selected_condition_1st_field = null;
                if (ConditionEntry["condition_1st_field"] != null && ConditionEntry["condition_1st_field"].ToString().Length > 0)
                {
                    selected_condition_1st_field = ConditionEntry["condition_1st_field"].ToString();
                }
                  Control WhereControl = LoadControl("../Controls/SpreadsheetWhereTest.ascx", selected_condition_1st_field);

                if (State["SpreadsheetError"] != null)
                {
                    Message.Text = State["SpreadsheetError"].ToString();
                    State["SpreadsheetError"] = null;
                    State["DBCommands"] = null;
                    State["SelectedDatabaseTable"] = null;
                    State["SelectedSqlCommand"] = null;
                    return;
                }

                where_node.Controls.Add(WhereControl);

                command_node.Nodes.Add(where_node);

                if (ConditionEntry["condition_operation"] != null && ConditionEntry["condition_operation"].ToString().Length > 0)
                {
                    string condition_operation = ConditionEntry["condition_operation"].ToString();
                    ((HtmlInputText)WhereControl.FindControl("condition_operation")).Value = condition_operation;
                }

                if (ConditionEntry["field_operation"] != null && ConditionEntry["field_operation"].ToString().Length > 0)
                {
                    string field_operation = ConditionEntry["field_operation"].ToString();
                    ((HtmlInputText)WhereControl.FindControl("field_operation")).Value = field_operation;
                }

                TestWhereValueMap[i_condition] = (HtmlInputText)WhereControl.FindControl("condition_2nd_field");

                i_condition++;
                sub_command_index++;
            }
        }
        Hashtable DBOrderBy = (Hashtable)CommandEntry["order_by"];
        if (DBOrderBy != null)
        {
            RadTreeNode orderBy_node = new RadTreeNode();
            orderBy_node.CssClass = "RadTreeView";
            orderBy_node.Category = "order_by";
            orderBy_node.PostBack = false;
            State["SelectedDatabaseTable"] = selected_table;
            string selected_sort_field = null;
            if (DBOrderBy["sort_field"] != null && DBOrderBy["sort_field"].ToString().Length > 0)
            {
                selected_sort_field = DBOrderBy["sort_field"].ToString();
            }

            Control OrderByControl = LoadControl("../Controls/DatabaseOrderByTest.ascx", selected_sort_field);
            if (State["SpreadsheetError"] != null)
            {
                Message.Text = State["SpreadsheetError"].ToString();
                State["SpreadsheetError"] = null;
                State["DBCommands"] = null;
                State["SelectedDatabaseTable"] = null;
                State["SelectedSqlCommand"] = null;
                return;
            }

            orderBy_node.Controls.Add(OrderByControl);
            command_node.Nodes.Add(orderBy_node);

            if (DBOrderBy["sort_direction"] != null && DBOrderBy["sort_direction"].ToString().Length > 0)
            {
                string sort_direction = DBOrderBy["sort_direction"].ToString();
                ((HtmlInputText)OrderByControl.FindControl("sort_direction")).Value = sort_direction;
            }
            sub_command_index++;
        }

        command_node.ExpandChildNodes();

        SpreadsheetCommandView.ExpandAllNodes();
    }