读取XML格式文件内容

前端之家收集整理的这篇文章主要介绍了读取XML格式文件内容前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.XML文件内容

<?xml version="1.0" encoding="utf-8" ?>
<ReportConfig>
  <Report ID="1" Title="The New Donor Information" >
    <Params>
      <ParamItem ParaType="ProfileTypeCheckBox" ParaTitle="機構類別" Para1Name="@ProfileTypeIds" />
      <ParamItem ParaType="DateRange" ParaTitle="成為捐款者日期" Para1Name="@StartDate" Para2Name="@EndDate"/>
      <ParamItem ParaType="EnabledStatus" ParaTitle="狀態" Para1Name="@EnabledStatus" />
    </Params>
    <sqlStatement>
      <![CDATA[
	SELECT * FROM [Profile] 
	WHERE MergeProfileID is null AND Status=1 AND case when len(@ProfileTypeIds)>0 then charindex(','+cast(ProfileType as varchar)+',','+@ProfileTypeIds+',') else 1 end >0 
		AND IsDonor=1 AND DonorDate BETWEEN @StartDate AND @EndDate 
      ]]>
    </sqlStatement>
  </Report>

  <Report ID="2" Title="The InKindItem Information">
    <Params>
      <ParamItem ParaType="DateRange" ParaTitle="饋贈日期" Para1Name="@StartDate" Para2Name="@EndDate"  Default1Value="-365" Default2Value="0" ConditionTitle="InKindItemDate"/>
    </Params>
    <sqlStatement>
      <![CDATA[
select * 
from ProfileInKindItem
where InKindDate between @StartDate and @EndDate
    
        ]]>
    </sqlStatement>
  </Report>    
</ReportConfig>


2. 定义类

public enum ReportTemplateType
{
AnalysisTool,
MgtAnalysis
}

    /// <summary>
    /// 主表報定義
    /// </summary>
    public class ReportAdapterSection
    {
        public string ID
        {
            get;
            set;
        }
        public string Title
        {
            get;
            set;
        }

        public string MastersqlStatement
        {
            get;
            set;
        }
        public List<ReportParamSection> ParamSettings
        {
            get;
            set;
        }
        public string UniqueKey
        {
            get;
            set;
        }
        public string SummaryAmtOrNum
        {
            get;
            set;
        }
        public bool IsAddTotal
        {
            get;
            set;
        }
        public string Remark1
        {
            get;
            set;
        }
        public string Remark2
        {
            get;
            set;
        }
        public string Remark3
        {
            get;
            set;
        }
    }


    /// <summary>
    /// 報表參數:應用到sql語句
    /// </summary>
    public class ReportParamSection
    {
        public string MainID
        {
            get;
            set;
        }
        public string Title
        {
            get;
            set;
        }
        public ReportParaType Type
        {
            get;
            set;
        }
        public string[] Params
        {
            get;
            set;
        }
        public string[] DefaultValues
        {
            get;
            set;
        }
        public string ConditionTitle
        {
            get;
            set;
        }
    }


3.获取实体类:

    /// <summary>
    /// XML报表实体类
    /// </summary>
    public static class ReportAdapterUtility
    {
        /// <summary>
        /// 獲取參數的值
        /// </summary>
        public static Dictionary<string,object> GetParamNameValues(ReportAdapterSection section,List<HtmlTableRow> postTableRows)
        {
            string key = "_" + section.ID;
            Dictionary<string,object> paras = new Dictionary<string,object>();
            for (int i = 0; i < section.ParamSettings.Count; i++)
            {
                var paraSetting = section.ParamSettings[i];
                var cotainerCell = postTableRows[i].Cells[1];
                switch (paraSetting.Type)
                {
                    case ReportParaType.DateRange:
                        DatePicker datePicker1 = cotainerCell.FindControl(paraSetting.Params[0] + key) as DatePicker;
                        DatePicker datePicker2 = cotainerCell.FindControl(paraSetting.Params[1] + key) as DatePicker;
                        if (datePicker1.SelectedDate.HasValue)
                        {
                            paras.Add(paraSetting.Params[0],datePicker1.SelectedDate);
                        }
                        else
                        {
                            paras.Add(paraSetting.Params[0],"1900-01-01");
                        }
                        if (datePicker2.SelectedDate.HasValue)
                        {
                            paras.Add(paraSetting.Params[1],datePicker2.SelectedDate);
                        }
                        else
                        {
                            paras.Add(paraSetting.Params[1],"9999-12-31");
                        }
                        break;
                    case ReportParaType.IntRange:
                        TextBox intTextBox1 = cotainerCell.FindControl(paraSetting.Params[0] + key) as TextBox;
                        int intValue1 = 0;
                        if (int.TryParse(intTextBox1.Text,out intValue1))
                        {
                            paras.Add(paraSetting.Params[0],intValue1);
                        }
                        else
                        {
                            paras.Add(paraSetting.Params[0],0);
                        }
                        TextBox intTextBox2 = cotainerCell.FindControl(paraSetting.Params[1] + key) as TextBox;
                        int intValue2 = 0;
                        if (int.TryParse(intTextBox2.Text,out intValue2))
                        {
                            paras.Add(paraSetting.Params[1],intValue2);
                        }
                        else
                        {
                            paras.Add(paraSetting.Params[1],99999999);
                        }
                        break;
                    case ReportParaType.MoneyRange:
                        TextBox MoneyTextBox1 = cotainerCell.FindControl(paraSetting.Params[0] + key) as TextBox;
                        decimal moneyValue1 = 0;
                        if (decimal.TryParse(MoneyTextBox1.Text,out moneyValue1))
                        {
                            paras.Add(paraSetting.Params[0],moneyValue1);
                        }
                        else
                        {
                            paras.Add(paraSetting.Params[0],-99999999);
                        }
                        TextBox MoneyTextBox2 = cotainerCell.FindControl(paraSetting.Params[1] + key) as TextBox;
                        decimal moneyValue2 = 0;
                        if (decimal.TryParse(MoneyTextBox2.Text,out moneyValue2))
                        {
                            paras.Add(paraSetting.Params[1],moneyValue2);
                        }
                        else
                        {
                            paras.Add(paraSetting.Params[1],99999999);
                        }
                        break;
                    case ReportParaType.ServiceNatureID:
                        DropDownList ddl_ServiceNature = cotainerCell.FindControl(paraSetting.Params[0] + key) as DropDownList;
                        paras.Add(paraSetting.Params[0],ddl_ServiceNature.SelectedValue);
                        break;
                    case ReportParaType.EventID:
                        DropDownList ddl_Event = cotainerCell.FindControl(paraSetting.Params[0] + key) as DropDownList;
                        paras.Add(paraSetting.Params[0],ddl_Event.SelectedValue);
                        break;
                    case ReportParaType.ProfileTypeCheckBox:
                        CheckBoxList cbl_ProfileType = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        string ids = cbl_ProfileType.GetSelectedValues(t => int.Parse(t)).ToString(t => t.ToString(),",");
                        paras.Add(paraSetting.Params[0],ids);
                        break;
                    case ReportParaType.DonationStatusCheckBox:
                        CheckBoxList cbl_DonationStatus = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        string DonationStatusIds = cbl_DonationStatus.GetSelectedValues(t => int.Parse(t)).ToString(t => t.ToString(),DonationStatusIds);
                        break;
                    case ReportParaType.ServiceNatureCheckBox:
                        CheckBoxList cbl_ServiceNature = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        string ServiceNatureIds = cbl_ServiceNature.GetSelectedValues(t => int.Parse(t)).ToString(t => t.ToString(),");
                        string rightServiceNatureIds = CommonMethod.GetReportServiceNatureRights();
                        paras.Add(paraSetting.Params[0],string.IsNullOrWhiteSpace(ServiceNatureIds) ? rightServiceNatureIds : ServiceNatureIds);
                        break;
                    case ReportParaType.EnabledStatus:
                        CheckBoxList cbl_EnabledStatus = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        string EnabledStatusIds = cbl_EnabledStatus.GetSelectedValues(t => int.Parse(t)).ToString(t => t.ToString(),");
                        EnabledStatusIds = EnabledStatusIds == "1,0" ? "" : EnabledStatusIds;
                        paras.Add(paraSetting.Params[0],EnabledStatusIds);
                        break;
                    case ReportParaType.HCCCheckBox:
                        CheckBoxList cbl_HCCCheckBox = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        string HccIds = cbl_HCCCheckBox.GetSelectedValues(t => int.Parse(t)).ToString(t => t.ToString(),HccIds);
                        break;
                    case ReportParaType.IsVip:
                        CheckBoxList cbl_IsVip = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        string VipIds = cbl_IsVip.GetSelectedValues(t => int.Parse(t)).ToString(t => t.ToString(),");
                        VipIds = VipIds == "1,0" ? "" : VipIds;
                        paras.Add(paraSetting.Params[0],VipIds);
                        break;
                }
            }
            return paras;
        }

        /// <summary>
        /// 獲取參數條件表達式
        /// </summary>
        public static string GetParamCondition(ReportAdapterSection section,List<HtmlTableRow> postTableRows)
        {
            string key = "_" + section.ID;
            string condition = string.Empty;
            for (int i = 0; i < section.ParamSettings.Count; i++)
            {
                var paraSetting = section.ParamSettings[i];
                var cotainerCell = postTableRows[i].Cells[1];
                string where = string.Empty;
                switch (paraSetting.Type)
                {
                    case ReportParaType.DateRange:
                        DatePicker datePicker1 = cotainerCell.FindControl(paraSetting.Params[0] + key) as DatePicker;
                        DatePicker datePicker2 = cotainerCell.FindControl(paraSetting.Params[1] + key) as DatePicker;
                        string dateCondition = string.IsNullOrWhiteSpace(paraSetting.ConditionTitle) ? "Donation Date" : paraSetting.ConditionTitle;
                        if (!string.IsNullOrWhiteSpace(datePicker1.SelectedDate.ToString()))
                        {
                            where = dateCondition + ": From " + datePicker1.SelectedDate.Value.ToShortDateString();
                        }
                        if (!string.IsNullOrWhiteSpace(datePicker2.SelectedDate.ToString()))
                        {
                            if (!string.IsNullOrWhiteSpace(datePicker1.SelectedDate.ToString()))
                            {
                                where = dateCondition + ": From " + datePicker1.SelectedDate.Value.ToShortDateString() + " to " + datePicker2.SelectedDate.Value.ToShortDateString();
                            }
                            else
                            {
                                where = dateCondition + ": to " + datePicker2.SelectedDate.Value.ToShortDateString();
                            }
                        }
                        break;
                    case ReportParaType.IntRange:
                        TextBox intTextBox1 = cotainerCell.FindControl(paraSetting.Params[0] + key) as TextBox;
                        TextBox intTextBox2 = cotainerCell.FindControl(paraSetting.Params[1] + key) as TextBox;
                        int intValue1 = 0;
                        int intValue2 = 0;
                        string countCondition = string.IsNullOrWhiteSpace(paraSetting.ConditionTitle) ? "Donation Count" : paraSetting.ConditionTitle;
                        if (int.TryParse(intTextBox1.Text,out intValue1))
                        {
                            where = countCondition + ": From " + intValue1.ToString();
                        }
                        if (int.TryParse(intTextBox2.Text,out intValue2))
                        {
                            if (intValue1 > 0)
                            {
                                where += " To " + intValue2.ToString();
                            }
                            else
                            {
                                where = countCondition + ": To " + intValue2.ToString();
                            }
                        }
                        break;
                    case ReportParaType.MoneyRange:
                        TextBox MoneyTextBox1 = cotainerCell.FindControl(paraSetting.Params[0] + key) as TextBox;
                        TextBox MoneyTextBox2 = cotainerCell.FindControl(paraSetting.Params[1] + key) as TextBox;
                        decimal moneyValue1 = 0;
                        decimal moneyValue2 = 0;
                        string amountCondition = string.IsNullOrWhiteSpace(paraSetting.ConditionTitle) ? "Donation Amount" : paraSetting.ConditionTitle;
                        if (decimal.TryParse(MoneyTextBox1.Text,out moneyValue1))
                        {
                            where = amountCondition + ": From " + moneyValue1.ToString();
                        }
                        if (decimal.TryParse(MoneyTextBox2.Text,out moneyValue2))
                        {
                            if (moneyValue1 > 0)
                            {
                                where += " To " + moneyValue2.ToString();
                            }
                            else
                            {
                                where = amountCondition + ": To " + moneyValue2.ToString();
                            }
                        }
                        break;
                    case ReportParaType.ServiceNatureID:
                        DropDownList ddl_ServiceNature = cotainerCell.FindControl(paraSetting.Params[0] + key) as DropDownList;
                        int ID = int.Parse(ddl_ServiceNature.SelectedValue);
                        string ServiceNatureName = string.Empty;
                        ServiceNatureORM dataModel = BaseInfoSRV.GetServiceNatureByID(ID);
                        ServiceNatureName = dataModel == null ? string.Empty : dataModel.NameEN;

                        where = "Service Nature: " + ServiceNatureName;
                        break;
                    case ReportParaType.EventID:
                        DropDownList ddl_Event = cotainerCell.FindControl(paraSetting.Params[0] + key) as DropDownList;
                        if (ddl_Event.Items.Count > 0)
                        {
                            where = "Event: " + ddl_Event.SelectedItem.Text;
                        }
                        break;
                    case ReportParaType.ProfileTypeCheckBox:
                        CheckBoxList cbl_ProfileType = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        foreach (ListItem item in cbl_ProfileType.Items)
                        {
                            if (item.Selected)
                            {
                                where += (where.Length > 0 ? "," : "") + item.Text;
                            }
                        }
                        where = string.IsNullOrWhiteSpace(where) ? "" : (Environment.NewLine + "ProfileType: " + where);
                        break;
                    case ReportParaType.DonationStatusCheckBox:
                        CheckBoxList cbl_DonationStatus = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        foreach (ListItem item in cbl_DonationStatus.Items)
                        {
                            if (item.Selected)
                            {
                                where += (where.Length > 0 ? "," : "") + item.Text;
                            }
                        }
                        where = string.IsNullOrWhiteSpace(where) ? "" : (Environment.NewLine + "Donation Status: " + where);
                        break;
                    case ReportParaType.ServiceNatureCheckBox:
                        CheckBoxList cbl_ServiceNature = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        foreach (ListItem item in cbl_ServiceNature.Items)
                        {
                            if (item.Selected)
                            {
                                where += (where.Length > 0 ? "," : "") + item.Text;
                            }
                        }
                        where = string.IsNullOrWhiteSpace(where) ? "" : (Environment.NewLine + "Service Nature: " + where);
                        break;
                    case ReportParaType.EnabledStatus:
                        CheckBoxList cbl_EnabledStatus = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        foreach (ListItem item in cbl_EnabledStatus.Items)
                        {
                            if (item.Selected)
                            {
                                where += (where.Length > 0 ? "," : "") + item.Text;
                            }
                        }
                        where = string.IsNullOrWhiteSpace(where) ? "" : (Environment.NewLine + "Enabled Status: " + where);
                        break;
                    case ReportParaType.HCCCheckBox:
                        CheckBoxList cbl_HCCCheckBox = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        foreach (ListItem item in cbl_HCCCheckBox.Items)
                        {
                            if (item.Selected)
                            {
                                where += (where.Length > 0 ? "," : "") + item.Text;
                            }
                        }
                        where = string.IsNullOrWhiteSpace(where) ? "" : (Environment.NewLine + "HCC Item: " + where);
                        break;
                    case ReportParaType.IsVip:
                        CheckBoxList cbl_IsVip = cotainerCell.FindControl(paraSetting.Params[0] + key) as CheckBoxList;
                        foreach (ListItem item in cbl_IsVip.Items)
                        {
                            if (item.Selected)
                            {
                                where += (where.Length > 0 ? "," : "") + item.Text;
                            }
                        }
                        where = string.IsNullOrWhiteSpace(where) ? "" : (Environment.NewLine + "Haven Of Hope VIP: " + where);
                        break;
                }
                condition += string.IsNullOrWhiteSpace(where) ? "" : (where + "\r");
            }
            return condition;
        }


        /// <summary>
        /// 获取一个XML档所有ID和报表名称
        /// </summary>
        public static Dictionary<string,string> GetReportAdapterSectionList(ProfileRole RoleType,ReportTemplateType TemplateType)
        {
            XmlDocument xmlDoc = new XmlDocument();
            string configFile = GetReportConfigFile(RoleType,TemplateType);
            xmlDoc.Load(configFile);
            XmlNodeList nodes = xmlDoc.SelectSingleNode("ReportConfig").ChildNodes;
            Dictionary<string,string> reportNameList = new Dictionary<string,string>();
            foreach (XmlElement node in nodes)
            {
                string ID = node.Attributes["ID"].Value;
                string Title = node.Attributes["Title"].Value;
                reportNameList.Add(ID,Title);
            }
            return reportNameList;
        }


        /// <summary>
        /// 获取一个报表的参数
        /// </summary>
        public static ReportAdapterSection GetReportAdapterSectionByID(string ReportID,ProfileRole RoleType,ReportTemplateType TemplateType)
        {
            ReportAdapterSection reportModel = new ReportAdapterSection();
            XmlDocument xmlDoc = new XmlDocument();
            string configFile = GetReportConfigFile(RoleType,TemplateType);
            xmlDoc.Load(configFile);
            XmlNodeList nodes = xmlDoc.SelectSingleNode("ReportConfig").ChildNodes;
            List<ReportParamSection> list = new List<ReportParamSection>();

            foreach (XmlElement node in nodes)
            {
                if (node.HasChildNodes && node.Attributes["ID"].Value == ReportID)
                {
                    string MainID = node.Attributes["ID"].Value;
                    reportModel.ID = MainID;
                    reportModel.Title = node.Attributes["Title"].Value;
                    string UniqueKey = string.Empty;
                    if (node.Attributes["UniqueKey"] != null)
                    {
                        UniqueKey = node.Attributes["UniqueKey"].Value;
                    }
                    reportModel.UniqueKey = UniqueKey;
                    string SummaryAmtOrNum = string.Empty;
                    if (node.Attributes["SummaryAmtOrNum"] != null)
                    {
                        SummaryAmtOrNum = node.Attributes["SummaryAmtOrNum"].Value;
                    }
                    reportModel.SummaryAmtOrNum = SummaryAmtOrNum;

                    bool IsAddTotal = false;
                    if (node.Attributes["IsAddTotal"] != null)
                    {
                        IsAddTotal = node.Attributes["IsAddTotal"].Value == "1" ? true : false;
                    }
                    reportModel.IsAddTotal = IsAddTotal;
                    XmlNode paramsNode = node.SelectSingleNode("Params");
                    if (paramsNode != null && paramsNode.HasChildNodes)
                    {
                        foreach (XmlElement item in paramsNode)
                        {
                            ReportParamSection model = new ReportParamSection();
                            model.MainID = MainID;
                            model.Title = item.Attributes["ParaTitle"].Value;
                            model.Type = (ReportParaType)Enum.Parse(typeof(ReportParaType),item.Attributes["ParaType"].Value);

                            //参数
                            string paras1 = string.Empty,paras2 = string.Empty;
                            paras1 = item.Attributes["Para1Name"].Value;
                            if (item.Attributes["Para2Name"] != null)
                            {
                                paras2 = item.Attributes["Para2Name"].Value;
                            }
                            model.Params = new string[] { paras1,paras2 };
                            //默认值
                            string dvalue1 = string.Empty,dvalue2 = string.Empty;
                            if (item.Attributes["Default1Value"] != null)
                            {
                                dvalue1 = item.Attributes["Default1Value"].Value;
                            }
                            if (item.Attributes["Default2Value"] != null)
                            {
                                dvalue2 = item.Attributes["Default2Value"].Value;
                            }
                            model.DefaultValues = new string[] { dvalue1,dvalue2 };
                            //条件标题
                            string ConditionTitle = string.Empty;
                            if (item.Attributes["ConditionTitle"] != null)
                            {
                                ConditionTitle = item.Attributes["ConditionTitle"].Value;
                            }
                            model.ConditionTitle = ConditionTitle;
                            list.Add(model);
                        }
                    }
                    XmlNode sqlNode = node.SelectSingleNode("sqlStatement");
                    reportModel.MastersqlStatement = sqlNode.InnerText;
                    if (node.SelectSingleNode("Remark1") != null)
                    {
                        reportModel.Remark1 = node.SelectSingleNode("Remark1").Attributes["Text"].Value;
                    }
                    if (node.SelectSingleNode("Remark2") != null)
                    {
                        reportModel.Remark2 = node.SelectSingleNode("Remark2").Attributes["Text"].Value;
                    }
                    if (node.SelectSingleNode("Remark3") != null)
                    {
                        reportModel.Remark3 = node.SelectSingleNode("Remark3").Attributes["Text"].Value;
                    }
                }
            }
            reportModel.ParamSettings = list;
            return reportModel;
        }


        /// <summary>
        /// 由ReportAdapterSection创建TableRow
        /// </summary>
        public static List<HtmlTableRow> CreateTableRowList(ReportAdapterSection section)
        {
            List<HtmlTableRow> ParamToControls = new List<HtmlTableRow>();
            foreach (ReportParamSection item in section.ParamSettings)
            {
                ParamToControls.Add(CreateParamInputTableRow(item));
            }
            return ParamToControls;
        }

        /// <summary>
        /// 自动创建控件
        /// </summary>
        private static HtmlTableRow CreateParamInputTableRow(ReportParamSection obj)
        {
            string ServiceNatureIds = string.Empty;
            string key = "_" + obj.MainID;
            HtmlTableRow row = new HtmlTableRow();
            HtmlTableCell cell1 = new HtmlTableCell();
            cell1.InnerText = obj.Title + ":";
            cell1.Attributes["class"] = "capitalField field";
            row.Cells.Add(cell1);
            HtmlTableCell cell2 = new HtmlTableCell();
            cell2.Attributes["class"] = "field";
            row.Cells.Add(cell2);
            switch (obj.Type)
            {
                case ReportParaType.DateRange:
                    Literal dlit1 = new Literal() { Text = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td style=\"width: 15px; text-align: center\">由</td><td style=\"width: 155px;\">" };
                    Literal dlit2 = new Literal() { Text = "</td><td style=\"width: 20px; text-align: center\">至</td><td style=\"width: 180px;\">" };
                    Literal dlit3 = new Literal() { Text = "</td></tr></table>" };
                    DatePicker datePicker1 = new DatePicker();
                    DatePicker datePicker2 = new DatePicker();
                    datePicker1.Width = 150;
                    datePicker1.ID = obj.Params[0] + key;
                    datePicker2.Width = 150;
                    datePicker2.ID = obj.Params[1] + key;
                    int days;
                    if (obj.DefaultValues[0] != null)
                    {
                        if (int.TryParse(obj.DefaultValues[0],out days))
                        {
                            datePicker1.SelectedDate = DateTime.Today.AddDays(days);
                        }
                    }
                    if (obj.DefaultValues[1] != null)
                    {
                        if (int.TryParse(obj.DefaultValues[1],out days))
                        {
                            datePicker2.SelectedDate = DateTime.Today.AddDays(days);
                        }
                    }
                    cell2.Controls.Add(dlit1);
                    cell2.Controls.Add(datePicker1);
                    cell2.Controls.Add(dlit2);
                    cell2.Controls.Add(datePicker2);
                    cell2.Controls.Add(dlit3);
                    break;
                case ReportParaType.IntRange:
                    Literal ilit1 = new Literal() { Text = "  由  " };
                    Literal ilit2 = new Literal() { Text = "  至  " };
                    TextBox txt_MinCount = new TextBox();
                    TextBox txt_MaxCount = new TextBox();
                    txt_MinCount.ID = obj.Params[0] + key;
                    txt_MaxCount.ID = obj.Params[1] + key;
                    int count;
                    txt_MinCount.Text = "";
                    if (obj.DefaultValues[0] != null)
                    {
                        if (int.TryParse(obj.DefaultValues[0],out count))
                        {
                            txt_MinCount.Text = count.ToString();
                        }
                    }
                    txt_MaxCount.Text = "";
                    if (obj.DefaultValues[1] != null)
                    {
                        if (int.TryParse(obj.DefaultValues[1],out count))
                        {
                            txt_MaxCount.Text = count.ToString();
                        }
                    }

                    cell2.Controls.Add(ilit1);
                    cell2.Controls.Add(txt_MinCount);
                    cell2.Controls.Add(ilit2);
                    cell2.Controls.Add(txt_MaxCount);
                    break;
                case ReportParaType.MoneyRange:
                    Literal mlit1 = new Literal() { Text = "  由  " };
                    Literal mlit2 = new Literal() { Text = "  至  " };
                    TextBox txt_MinAmount = new TextBox();
                    TextBox txt_MaxAmount = new TextBox();
                    txt_MinAmount.ID = obj.Params[0] + key;
                    txt_MaxAmount.ID = obj.Params[1] + key;
                    decimal amount;
                    txt_MinAmount.Text = "";
                    if (obj.DefaultValues[0] != null)
                    {
                        if (decimal.TryParse(obj.DefaultValues[0],out amount))
                        {
                            txt_MinAmount.Text = amount.ToString();
                        }
                    }
                    txt_MaxAmount.Text = "";
                    if (obj.DefaultValues[1] != null)
                    {
                        if (decimal.TryParse(obj.DefaultValues[1],out amount))
                        {
                            txt_MaxAmount.Text = amount.ToString();
                        }
                    }
                    cell2.Controls.Add(mlit1);
                    cell2.Controls.Add(txt_MinAmount);
                    cell2.Controls.Add(mlit2);
                    cell2.Controls.Add(txt_MaxAmount);
                    break;
                case ReportParaType.ProfileTypeCheckBox:
                    CheckBoxList cbl_ProfileType = new CheckBoxList();
                    cbl_ProfileType.ID = obj.Params[0] + key;
                    cbl_ProfileType.DataSource = EnumDataUtility.GetEnumItemCollection<ProfileType>().ToList().Select(t => { return new { Text = t.Description,Value = t.Value }; });
                    cbl_ProfileType.DataTextField = "Text";
                    cbl_ProfileType.DataValueField = "Value";
                    cbl_ProfileType.DataBind();
                    cbl_ProfileType.RepeatColumns = 6;
                    cbl_ProfileType.RepeatDirection = RepeatDirection.Horizontal;
                    cbl_ProfileType.CssClass = "itemlist-mulrow-fixed";
                    cbl_ProfileType.Attributes["Width"] = "100%";
                    cell2.Controls.Add(cbl_ProfileType);
                    break;
                case ReportParaType.DonationStatusCheckBox:
                    CheckBoxList cbl_DonationStatus = new CheckBoxList();
                    cbl_DonationStatus.ID = obj.Params[0] + key;
                    cbl_DonationStatus.DataSource = EnumDataUtility.GetEnumItemCollection<DonationStatus>().ToList().Select(t => { return new { Text = t.Description,Value = t.Value }; });
                    cbl_DonationStatus.DataTextField = "Text";
                    cbl_DonationStatus.DataValueField = "Value";
                    cbl_DonationStatus.DataBind();
                    cbl_DonationStatus.RepeatColumns = 5;
                    cbl_DonationStatus.RepeatDirection = RepeatDirection.Horizontal;
                    cbl_DonationStatus.CssClass = "itemlist-mulrow-fixed";
                    cbl_DonationStatus.Attributes["Width"] = "100%";
                    cell2.Controls.Add(cbl_DonationStatus);
                    break;
                case ReportParaType.EnabledStatus:
                    CheckBoxList cbl_EnabledStatus = new CheckBoxList();
                    cbl_EnabledStatus.ID = obj.Params[0] + key;
                    cbl_EnabledStatus.DataSource = EnumDataUtility.GetEnumItemCollection<EnabledStatus>().ToList().Select(t => { return new { Text = t.Description,Value = t.Value }; });
                    cbl_EnabledStatus.DataTextField = "Text";
                    cbl_EnabledStatus.DataValueField = "Value";
                    cbl_EnabledStatus.DataBind();
                    cbl_EnabledStatus.RepeatColumns = 2;
                    cbl_EnabledStatus.RepeatDirection = RepeatDirection.Horizontal;
                    cbl_EnabledStatus.CssClass = "itemlist-mulrow-fixed";
                    cbl_EnabledStatus.Attributes["Width"] = "200";
                    cell2.Controls.Add(cbl_EnabledStatus);
                    break;
                case ReportParaType.ServiceNatureCheckBox:
                    CheckBoxList cbl_ServiceNature = new CheckBoxList();
                    cbl_ServiceNature.ID = obj.Params[0] + key;
                    ServiceNatureIds = CommonMethod.GetReportServiceNatureRights();
                    cbl_ServiceNature.DataSource = BaseInfoSRV.GetServiceNatureListByIds(ServiceNatureIds).ToList().Select(t => { return new ListItem() { Text = t.NameCN,Value = t.ID.ToString() }; }).ToList();
                    cbl_ServiceNature.DataTextField = "Text";
                    cbl_ServiceNature.DataValueField = "Value";
                    cbl_ServiceNature.DataBind();
                    cbl_ServiceNature.RepeatColumns = 5;
                    cbl_ServiceNature.RepeatDirection = RepeatDirection.Horizontal;
                    cbl_ServiceNature.CssClass = "itemlist-mulrow-fixed";
                    cbl_ServiceNature.Attributes["Width"] = "100%";
                    cell2.Controls.Add(cbl_ServiceNature);

                    break;
                case ReportParaType.ServiceNatureID:
                    DropDownList ddl_ServiceNature = new DropDownList();
                    ddl_ServiceNature.ID = obj.Params[0] + key;
                    ServiceNatureIds = CommonMethod.GetReportServiceNatureRights();
                    ddl_ServiceNature.DataSource = BaseInfoSRV.GetServiceNatureListByIds(ServiceNatureIds).ToList().Select(t => { return new ListItem() { Text = t.NameCN,Value = t.ID.ToString() }; }).ToList();
                    ddl_ServiceNature.DataTextField = "Text";
                    ddl_ServiceNature.DataValueField = "Value";
                    ddl_ServiceNature.DataBind();
                    ddl_ServiceNature.Width = 340;
                    cell2.Controls.Add(ddl_ServiceNature);
                    break;
                case ReportParaType.EventID:
                    DropDownList ddl_Event = new DropDownList();
                    ddl_Event.ID = obj.Params[0] + key;
                    ddl_Event.DataSource = ActivitySRV.GetAllEventList(true).ToList().Select(t => { return new ListItem() { Text = t.EventCode + " " + t.NameCN,Value = t.ID.ToString() }; }).ToList();
                    ddl_Event.DataTextField = "Text";
                    ddl_Event.DataValueField = "Value";
                    ddl_Event.DataBind();
                    ddl_Event.Width = 340;
                    cell2.Controls.Add(ddl_Event);
                    break;
                case ReportParaType.HCCCheckBox:
                    CheckBoxList cbl_HCC = new CheckBoxList();
                    cbl_HCC.ID = obj.Params[0] + key;
                    cbl_HCC.DataSource = ProfileSRV.GetProfilePropertyListByItemKey(ProfileEnumData.HCC.ToEnumDescriptionByType()).ToList().Select(t => { return new { Text = t.NameCN,Value = t.ItemTypeID }; });
                    cbl_HCC.DataTextField = "Text";
                    cbl_HCC.DataValueField = "Value";
                    cbl_HCC.DataBind();
                    cbl_HCC.RepeatColumns = 6;
                    cbl_HCC.RepeatDirection = RepeatDirection.Horizontal;
                    cbl_HCC.CssClass = "itemlist-mulrow-fixed";
                    cbl_HCC.Attributes["Width"] = "100%";
                    cell2.Controls.Add(cbl_HCC);
                    break;
                case ReportParaType.IsVip:
                    CheckBoxList cbl_IsVip = new CheckBoxList();
                    cbl_IsVip.ID = obj.Params[0] + key;
                    cbl_IsVip.DataSource = EnumDataUtility.GetEnumItemCollection<BoolToYesNo>().ToList().Select(t => { return new { Text = t.Description,Value = t.Value }; });
                    cbl_IsVip.DataTextField = "Text";
                    cbl_IsVip.DataValueField = "Value";
                    cbl_IsVip.DataBind();
                    cbl_IsVip.RepeatColumns = 2;
                    cbl_IsVip.RepeatDirection = RepeatDirection.Horizontal;
                    cbl_IsVip.CssClass = "itemlist-mulrow-fixed";
                    cbl_IsVip.Attributes["Width"] = "200";
                    cell2.Controls.Add(cbl_IsVip);
                    break;
            }
            return row;
        }


        /// <summary>
        /// 获取XML档文件路径
        /// </summary>
        private static string GetReportConfigFile(ProfileRole RoleType,ReportTemplateType TemplateType)
        {
            string folder = HttpContext.Current.Server.MapPath("~/Pages/Report/XML");
            string fileName = string.Empty;
            switch (TemplateType)
            {
                case ReportTemplateType.AnalysisTool:
                    switch (RoleType)
                    {
                        case ProfileRole.Donor:
                            fileName = "Donor_AnalysisTool.xml";
                            break;
                        case ProfileRole.KOL:
                            fileName = "KOL_AnalysisTool.xml";
                            break;
                        case ProfileRole.Media:
                            fileName = "Media_AnalysisTool.xml";
                            break;
                        case ProfileRole.PotentialSupporter:
                            fileName = "PS_AnalysisTool.xml";
                            break;
                        case ProfileRole.Volunteer:
                            fileName = "Volunteer_AnalysisTool.xml";
                            break;
                        default:
                            throw new InvalidCastException(RoleType.ToString());

                    }
                    break;
                case ReportTemplateType.MgtAnalysis:
                    switch (RoleType)
                    {
                        case ProfileRole.Donor:
                            fileName = "Donor_MgtAnalysis.xml";
                            break;
                        case ProfileRole.KOL:
                            fileName = "KOL_MgtAnalysis.xml";
                            break;
                        case ProfileRole.Media:
                            fileName = "Media_MgtAnalysis.xml";
                            break;
                        case ProfileRole.PotentialSupporter:
                            fileName = "PS_MgtAnalysis.xml";
                            break;
                        case ProfileRole.Volunteer:
                            fileName = "Volunteer_MgtAnalysis.xml";
                            break;
                        default:
                            throw new InvalidCastException(RoleType.ToString());
                    }
                    break;
                default:
                    throw new InvalidCastException(TemplateType.ToString());
            }
            return System.IO.Path.Combine(folder,fileName);
        }

    }
原文链接:https://www.f2er.com/xml/299873.html

猜你在找的XML相关文章