public ReportDataOperatorItem Copy()
        {
            ReportDataOperatorItem item = new ReportDataOperatorItem();

            item.ChannelName  = this.ChannelName;
            item.CodeName     = this.CodeName;
            item.Mo           = this.Mo;
            item.SPCode       = this.SPCode;
            item.MoType       = this.MoType;
            item.Province     = this.Province;
            item.RecordCount  = this.RecordCount;
            item.MoLength     = this.MoLength;
            item.OperatorType = this.OperatorType;
            return(item);
        }
        public static DataTable GetOperatorReport(DateTime startDate, DateTime endDate, int channleId, int clientChannleId, string mprovince, string moperator)
        {
            DataTable dt = new DataTable("DS");

            dt.Columns.Add("Operator");
            dt.Columns.Add("Province");
            dt.Columns.Add("Channel");
            dt.Columns.Add("Mo");
            dt.Columns.Add("RecordCount", typeof(int));
            dt.AcceptChanges();

            DataTable dtReportQuery = businessProxy.GetOperatorReport(startDate, endDate, channleId, clientChannleId, null, mprovince, moperator);

            List <ReportDataOperatorItem> reportDataProvinceItems = new List <ReportDataOperatorItem>();

            foreach (DataRow dr in dtReportQuery.Rows)
            {
                SPChannelWrapper channel = SPChannelWrapper.FindById((int)dr["ChannelID"]);
                SPClientChannelSettingWrapper channelSettingWrapper = SPClientChannelSettingWrapper.FindById((int)dr["ChannleClientID"]);

                string channelName = channel.Name;
                string moCode      = channelSettingWrapper.MoCode;
                int    recordCount = (int)dr["RecordCount"];
                string province    = dr["Province"].ToString();

                ReportDataOperatorItem reportDataProvinceItem = new ReportDataOperatorItem();
                reportDataProvinceItem.ChannelName = channelName.ToLower();
                reportDataProvinceItem.CodeName    = moCode.ToLower();
                if (string.IsNullOrEmpty(province))
                {
                    reportDataProvinceItem.Province = "未知省份";
                }
                else
                {
                    if (string.IsNullOrEmpty(province.Trim()))
                    {
                        reportDataProvinceItem.Province = "未知省份";
                    }
                    else
                    {
                        reportDataProvinceItem.Province = province.ToLower();
                    }
                }

                reportDataProvinceItem.RecordCount = recordCount;
                reportDataProvinceItem.Mo          = channelSettingWrapper.CommandCode.ToLower();
                if (channelSettingWrapper.ChannelCode == null)
                {
                    reportDataProvinceItem.SPCode = "";
                }
                else
                {
                    reportDataProvinceItem.SPCode = channelSettingWrapper.ChannelCode.ToLower();
                }


                if (channelSettingWrapper.CommandType == "1")
                {
                    reportDataProvinceItem.MoType = "1";
                }
                else if (channelSettingWrapper.CommandType == "2" || channelSettingWrapper.CommandType == "3" || channelSettingWrapper.CommandType == "4")
                {
                    reportDataProvinceItem.MoType = "2";
                }
                else
                {
                    reportDataProvinceItem.MoType = "0";
                }

                reportDataProvinceItem.MoLength     = reportDataProvinceItem.Mo.Length;
                reportDataProvinceItem.OperatorType = dr["Operator"].ToString();
                reportDataProvinceItems.Add(reportDataProvinceItem);
            }



            List <ReportDataOperatorItem> orderedItems = (from rap in reportDataProvinceItems
                                                          orderby rap.OperatorType, rap.Province, rap.ChannelName, rap.MoType, rap.Mo, rap.SPCode, rap.MoLength
                                                          select rap).ToList();

            List <ReportDataOperatorItem> groupItems = new List <ReportDataOperatorItem>();

            foreach (ReportDataOperatorItem oItem in orderedItems)
            {
                ReportDataOperatorItem item =
                    groupItems.Find(
                        p =>
                        (p.OperatorType == oItem.OperatorType && p.ChannelName == oItem.ChannelName &&
                         p.Province == oItem.Province && p.CodeName == oItem.CodeName));

                if (item != null)
                {
                    item.RecordCount = oItem.RecordCount + item.RecordCount;
                }
                else
                {
                    if (oItem.MoType == "2")
                    {
                        ReportDataOperatorItem mitem = (from rap in groupItems
                                                        where
                                                        (rap.OperatorType == oItem.OperatorType && rap.ChannelName == oItem.ChannelName &&
                                                         rap.Province == oItem.Province && rap.SPCode == oItem.SPCode &&
                                                         !oItem.Mo.Equals(rap.Mo) && oItem.Mo.Contains(rap.Mo))
                                                        orderby rap.MoLength
                                                        select rap).FirstOrDefault();

                        bool hasMain = (mitem != null);

                        if (hasMain)
                        {
                            mitem.RecordCount = oItem.RecordCount + mitem.RecordCount;

                            continue;
                        }
                    }

                    var addItem = oItem.Copy();

                    groupItems.Add(addItem);
                }
            }

            foreach (ReportDataOperatorItem groupItem in groupItems)
            {
                dt.Rows.Add(groupItem.OperatorType, groupItem.Province, groupItem.ChannelName, groupItem.CodeName,
                            groupItem.RecordCount);
            }



            dt.AcceptChanges();

            return(dt);
        }