//取出GridView数据源中的绑定对象集合
        private ETLSapTableResultCollection getDataByGridView(GridView grid, int sortNo)
        {
            ETLSapTableResultCollection result = new ETLSapTableResultCollection();

            for (int i = 0; i < grid.Rows.Count; i++)
            {
                ETLSapTableResult item = new ETLSapTableResult();
                item.EntityName   = grid.ToolTip;
                item.IsEnable     = ((CheckBox)grid.Rows[i].FindControl("cb_IsEnable")).Checked;
                item.IsPrimaryKey = ((CheckBox)grid.Rows[i].FindControl("cb_IsPrimaryKey")).Checked;
                item.FieldName    = ((Label)grid.Rows[i].FindControl("lbl_FieldName")).Text;
                item.FieldDesc    = ((Label)grid.Rows[i].FindControl("lbl_FieldDesc")).Text;

                FieldTypeEnum fieldType;
                FieldTypeEnum.TryParse(((Label)grid.Rows[i].FindControl("lbl_FieldType")).Text, out fieldType);
                item.FieldType = fieldType;

                item.FieldLength = Convert.ToInt32(((Label)grid.Rows[i].FindControl("lbl_FieldLength")).Text);
                item.IsIndex     = ((CheckBox)grid.Rows[i].FindControl("cb_IsIndex")).Checked;
                if (checkIsCommon.Checked)
                {
                    item.IsKey   = ((CheckBox)grid.Rows[i].FindControl("cb_IsKey")).Checked;
                    item.IsValue = ((CheckBox)grid.Rows[i].FindControl("cb_IsValue")).Checked;
                }

                item.RefTableName = ((HBDropDownList)grid.Rows[i].FindControl("ddl_RefTableName")).SelectedIndex == 0 ? string.Empty : ((HBDropDownList)grid.Rows[i].FindControl("ddl_RefTableName")).SelectedValue;
                item.RefFieldName = ((HBDropDownList)grid.Rows[i].FindControl("ddl_RefFieldName")).SelectedValue.Trim() == "" ? string.Empty : ((HBDropDownList)grid.Rows[i].FindControl("ddl_RefFieldName")).SelectedValue;
                item.SortNo       = sortNo;
                result.Add(item);
            }

            return(result);
        }
        private List <SapFieldDataItem> collectReapterData()
        {
            List <SapFieldDataItem> dataSource = new List <SapFieldDataItem>();

            if (rpt_Entities.Items.Count > 0)
            {
                for (int i = 0; i < this.rpt_Entities.Items.Count; i++)
                {
                    ETLSapTableResultCollection result = new ETLSapTableResultCollection();

                    var grid = (GridView)this.rpt_Entities.Items[i].FindControl("grid");

                    if (grid != null)
                    {
                        var dataItem = getDataByGridView(grid, i);

                        dataItem.ForEach(result.Add);

                        dataSource.Add(new SapFieldDataItem()
                        {
                            Key = grid.ToolTip,

                            Collection = result
                        });
                    }
                }
            }

            return(dataSource);
        }
        //保存实体及映射
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            try
            {
                var dataSource = collectReapterData();

                ETLSapTableResultCollection result = new ETLSapTableResultCollection();

                foreach (var sapFieldDataItem in dataSource)
                {
                    List <ETLSapTableResult> resultCollection = sapFieldDataItem.Collection.Where(p => p.IsEnable).ToList();

                    foreach (ETLSapTableResult etlSapTableResult in resultCollection)
                    {
                        result.Add(etlSapTableResult);
                    }
                }

                result.IsCommon = checkIsCommon.Checked;

                result.UepUsers      = this.hidd_Users.Value;
                result.SAPInstanceId = this.hidSAPInstanceId.Value;
                result.SAPInstanceId.CheckStringIsNullOrEmpty("sapInstanceId");
                ETLDEObjectOperations.Instance.AddETLEntityBySapTable(Request.QueryString["categoryid"], result);

                // HttpContext.Current.Response.Write("<script>alert('添加成功');window.returnValue=true;window.close();</script>");
                //return;
                //Response.End();
                //scriptStr = "<script>alert('添加成功');window.returnValue=true;window.close();</script>";
                WebUtility.ResponseShowClientMessageScriptBlock("添加成功!", "", "添加成功");
                WebUtility.RegisterOnLoadScriptBlock(this, "window.returnValue=true;window.close();");
            }
            catch (Exception ex)
            {
                WebUtility.ResponseShowClientMessageScriptBlock("操作失败!", ex.Message, "操作失败");
            }
        }
        public ETLSapTableResultCollection GetDatas(DataTable table)
        {
            ETLSapTableResultCollection resultList = new ETLSapTableResultCollection();

            var parentRows = table.Select();
            int sortNumber = 0;

            foreach (var item in parentRows)
            {
                sortNumber++;
                ETLSapTableResult result = new ETLSapTableResult();
                result.SortNo        = sortNumber;
                result.EntityName    = Convert.ToString(item["实体名"]);
                result.EntityDesc    = Convert.ToString(item["实体描述"]);
                result.DefaultValue  = Convert.ToString(item["默认值"]);
                result.IsMasterTable = Convert.ToString(item["主子标识"]) == "主" ? true : false;
                result.FieldName     = Convert.ToString(item["字段名"]);
                result.IsPrimaryKey  = bool.Parse(Convert.ToString(item["主键"]));
                if (result.IsPrimaryKey)
                {
                    result.IsEnable = true;
                }

                int fileLenth = Convert.ToInt32(item["字段长度"]);

                result.FieldType = SAPFileMapping.SAPFiledTypeToUEPFiledType(Convert.ToString(item["字段类型"]), ref fileLenth);;

                item["字段长度"] = fileLenth;

                result.FieldDesc = Convert.ToString(item["字段描述"]);

                result.FieldLength = int.Parse(Convert.ToString(item["字段长度"]));

                resultList.Add(result);
            }
            return(resultList);
        }
        public void CreateEntities(ETLSapTableResultCollection data)
        {
            data.NullCheck("SAP结构不能为Null");
            data.Any().FalseThrow("没有获取到SAP表结构");

            List <SapFieldDataItem> dataSource = new List <SapFieldDataItem>();

            //先将Reapter现在的数据源取出来
            dataSource = collectReapterData();

            //ETL实体获取表结构不可能获取多层级结构,即只能获取一张表的结构
            if (data.GroupBy(p => p.EntityName).Count() > 1)
            {
                WebUtility.ResponseShowClientErrorScriptBlock("获取表结构发生异常!", "", "错误");
                return;
            }

            if (dataSource.Any(p => p.Key.Equals(data.FirstOrDefault().EntityName)))
            {
                WebUtility.ResponseShowClientErrorScriptBlock("已存在相同的表!", "", "错误");
                return;
            }

            dataSource.Add(new SapFieldDataItem()
            {
                Key        = data.FirstOrDefault().EntityName,
                SortNo     = (dataSource.GroupBy(p => p.Key).Count()) + 1,
                Collection = data
            });


            rpt_Entities.DataSource = dataSource.OrderBy(p => p.SortNo);
            rpt_Entities.DataBind();

            SetDorpDownListItem(dataSource);
        }