示例#1
0
        /// <summary>
        /// Fills the default values for LIP.
        /// </summary>
        /// <param name="dg">The dg.</param>
        /// <param name="excluded">The excluded.</param>
        private void FillDefaultValues(DataGrid dg, DataGridItem excluded)
        {
            _ir = (ImportRequest)ViewState["_ir"];

            MappingElementBuilder meb = new MappingElementBuilder(_ir.MappingDocument);

            foreach (DataGridItem dgi in dg.Items)
            {
                if (excluded != null && excluded == dgi)
                {
                    continue;
                }
                string    mfName = dgi.Cells[0].Text;
                MetaField field  = FormController.GetMetaField(_className, mfName);

                MappingRule mr = meb.GetRuleByMetaField(mfName);
                if (mr != null && mr.RuleType == MappingRuleType.DefaultValue)
                {
                    if (field.IsEnum || field.IsReference)
                    {
                        DropDownList dd = (DropDownList)dgi.FindControl("ddColumn");
                        if (dd != null && dd.SelectedValue != "-1")
                        {
                            meb.AssignDefaultValueRule(mfName, dd.SelectedValue);
                        }
                    }
                    else
                    {
                        TextBox txt = (TextBox)dgi.FindControl("tbColumn");
                        if (txt != null)
                        {
                            meb.AssignDefaultValueRule(mfName, txt.Text);
                        }
                    }
                }
            }

            ViewState["_ir"] = _ir;
        }
示例#2
0
        /// <summary>
        /// Gets the mapping source.
        /// </summary>
        /// <returns></returns>
        private DataTable GetMappingSource()
        {
            if (ViewState["_ir"] == null)
                return null;
            _ir = (ImportRequest)ViewState["_ir"];

            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("metaFieldName", typeof(string)));
            dt.Columns.Add(new DataColumn("metaField", typeof(string)));
            dt.Columns.Add(new DataColumn("column", typeof(string)));
            DataRow dr;

            MetaClass mc = MetaDataWrapper.GetMetaClassByName(_className);
            MappingElementBuilder meb = new MappingElementBuilder(_ir.MappingDocument);
            foreach (MetaField mf in mc.Fields)
            {
                if (mf.InPrimaryKey || mf.IsBackReference || mf.IsLink || mf.IsReferencedField ||
                    !SchemaAttribute.CheckIsUpdatable(mf))
                    continue;

                if (mf.IsAggregation)
                {
                    #region IsAggregation
                    string aggrClassName = mf.Attributes.GetValue<string>(McDataTypeAttribute.AggregationMetaClassName);
                    MetaClass aggrClass = MetaDataWrapper.GetMetaClassByName(aggrClassName);
                    foreach (MetaField aggrField in aggrClass.Fields)
                    {
                        if (aggrField.InPrimaryKey || aggrField.IsBackReference || aggrField.IsLink ||
                            aggrField.IsReferencedField ||
                            !SchemaAttribute.CheckIsUpdatable(mf) ||
                            aggrField.Attributes.ContainsKey(McDataTypeAttribute.AggregationMark))
                            continue;

                        dr = dt.NewRow();
                        string uniqName = String.Format("{0}.{1}", mf.Name, aggrField.Name);
                        dr["metaFieldName"] = uniqName;
                        dr["metaField"] = CHelper.GetResFileString(aggrField.FriendlyName) + " (" + ((aggrField.GetOriginalMetaType() == null) ? aggrField.TypeName : CHelper.GetResFileString(aggrField.GetMetaType().FriendlyName)) + ")";

                        MappingRule mr = meb.GetRuleByMetaField(uniqName);

                        if (mr != null)
                            dr["column"] = mr.ColumnName;
                        else
                            dr["column"] = String.Empty;
                        dt.Rows.Add(dr);
                    }
                    #endregion

                    continue;
                }

                #region NonAggregation
                dr = dt.NewRow();
                dr["metaFieldName"] = mf.Name;
                dr["metaField"] = CHelper.GetResFileString(mf.FriendlyName) + " (" + ((mf.GetOriginalMetaType() == null) ? mf.TypeName : CHelper.GetResFileString(mf.GetMetaType().FriendlyName)) + ")";

                MappingRule mr1 = meb.GetRuleByMetaField(mf.Name);

                if (mr1 != null)
                    dr["column"] = mr1.ColumnName;
                else
                    dr["column"] = String.Empty;

                dt.Rows.Add(dr);
                #endregion
            }
            return dt;
        }
示例#3
0
        /// <summary>
        /// Fills the default values for LIP.
        /// </summary>
        /// <param name="dg">The dg.</param>
        /// <param name="excluded">The excluded.</param>
        private void FillDefaultValues(DataGrid dg, DataGridItem excluded)
        {
            _ir = (ImportRequest)ViewState["_ir"];

            MappingElementBuilder meb = new MappingElementBuilder(_ir.MappingDocument);

            foreach (DataGridItem dgi in dg.Items)
            {
                if (excluded != null && excluded == dgi)
                    continue;
                string mfName = dgi.Cells[0].Text;
                MetaField field = FormController.GetMetaField(_className, mfName);

                MappingRule mr = meb.GetRuleByMetaField(mfName);
                if (mr != null && mr.RuleType == MappingRuleType.DefaultValue)
                {
                    if (field.IsEnum || field.IsReference)
                    {
                        DropDownList dd = (DropDownList)dgi.FindControl("ddColumn");
                        if (dd != null && dd.SelectedValue != "-1")
                            meb.AssignDefaultValueRule(mfName, dd.SelectedValue);
                    }
                    else
                    {
                        TextBox txt = (TextBox)dgi.FindControl("tbColumn");
                        if (txt != null)
                            meb.AssignDefaultValueRule(mfName, txt.Text);
                    }
                }
            }

            ViewState["_ir"] = _ir;
        }
示例#4
0
        /// <summary>
        /// Handles the ItemDataBound event of the dgMapping control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridItemEventArgs"/> instance containing the event data.</param>
        void dgMapping_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            DropDownList ddi = (DropDownList)e.Item.FindControl("ddColumns");
            if (ddi != null)
            {

                string mfName = e.Item.Cells[0].Text;

                #region Commented  may be needed
                //string ownFieldName = mfName;
                //string aggrFieldName = String.Empty;
                //string aggrClassName = String.Empty;
                //MetaClass ownClass = MetaDataWrapper.GetMetaClassByName(_className);
                //MetaClass aggrClass = null;
                //MetaField ownField = null;
                //MetaField aggrField = null;
                //if (ownFieldName.Contains("."))
                //{
                //    string[] mas = ownFieldName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                //    ownFieldName = mas[0];
                //    aggrFieldName = mas[1];
                //    ownField = MetaDataWrapper.GetMetaFieldByName(ownClass, ownFieldName);
                //    aggrClassName = ownField.Attributes.GetValue<string>(McDataTypeAttribute.AggregationMetaClassName);
                //    aggrField = MetaDataWrapper.GetMetaFieldByName(aggrClassName, aggrFieldName);
                //}
                //else
                //    ownField = MetaDataWrapper.GetMetaFieldByName(ownClass, ownFieldName);
                #endregion

                _ir = (ImportRequest)ViewState["_ir"];

                MetaField field = FormController.GetMetaField(_className, mfName);
                MappingElementBuilder meb = new MappingElementBuilder(_ir.MappingDocument);
                MappingRule mr = meb.GetRuleByMetaField(mfName);

                ddi.Items.Clear();
                ddi.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.Common", "tNotSetValue").ToString(), "-1"));
                if (field.GetOriginalMetaType() != null)
                    ddi.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.Common", "tDefaultValue").ToString(), "0"));

                foreach (DataColumn dc in _ir.Data.Tables[0].Columns)
                    ddi.Items.Add(new ListItem(dc.ColumnName, dc.ColumnName));

                string val = "-1";
                if (mr != null)
                {
                    if (mr.RuleType == MappingRuleType.DefaultValue)
                        val = "0";
                    else if (mr.RuleType == MappingRuleType.CopyValue)
                        val = mr.ColumnName;
                }
                CHelper.SafeSelect(ddi, val);

                TextBox txt = (TextBox)e.Item.FindControl("tbColumn");
                DropDownList dd = (DropDownList)e.Item.FindControl("ddColumn");
                switch (val)
                {
                    case "-1":	//Not Set
                        txt.Visible = false;
                        dd.Visible = false;
                        break;
                    case "0":	//Default Value
                        if (field.IsEnum)
                        {
                            dd.Visible = true;
                            txt.Visible = false;
                            dd.Items.Clear();
                            MetaFieldType mft = field.GetMetaType();
                            foreach (MetaEnumItem mei in mft.EnumItems)
                                dd.Items.Add(new ListItem(CHelper.GetResFileString(mei.Name), mei.Handle.ToString()));
                            if (!String.IsNullOrEmpty(mr.DefaultValue))
                                CHelper.SafeSelect(dd, mr.DefaultValue);
                        }
                        else if (field.IsReference)
                        {
                            dd.Visible = true;
                            txt.Visible = false;
                            dd.Items.Clear();
                            string refClassName = field.Attributes.GetValue<string>(McDataTypeAttribute.ReferenceMetaClassName);
                            MetaClass refClass = MetaDataWrapper.GetMetaClassByName(refClassName);
                            EntityObject[] list = BusinessManager.List(refClassName, (new FilterElementCollection()).ToArray());

                            dd.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.Common", "tNotSetValue").ToString(), "-1"));
                            foreach (EntityObject eo in list)
                                dd.Items.Add(new ListItem(CHelper.GetResFileString(eo[refClass.TitleFieldName].ToString()), eo.PrimaryKeyId.Value.ToString()));
                            if (!String.IsNullOrEmpty(mr.DefaultValue))
                                CHelper.SafeSelect(dd, mr.DefaultValue);
                        }
                        else
                        {
                            dd.Visible = false;
                            txt.Visible = true;
                            txt.Text = mr.DefaultValue;
                        }
                        break;
                    default:	//CopyValue
                        txt.Visible = false;
                        dd.Visible = false;
                        break;
                }

                //Update UpdatePanel with lbl & txt && dd (upValues)
                foreach (Control c in e.Item.Cells[3].Controls)
                {
                    if (c is UpdatePanel)
                        ((UpdatePanel)c).Update();
                }

            }
        }
示例#5
0
        /// <summary>
        /// Creates the default name of the mapping by.
        /// </summary>
        private static FieldMathResult CreateMapingByFriendlyNameComparison(DataColumn column, MetaClass dstClass,
																		   string prefix, FieldMathResult prevMatchResult, 
																		   MappingElementBuilder builder)
        {
            FieldMathResult retVal = prevMatchResult;
            foreach (MetaField metaField in dstClass.Fields)
            {
                string mappedFieldName = prefix + metaField.Name;
                // Skip always maped metaField
                if (builder.GetRuleByMetaField(mappedFieldName) != null)
                    continue;
                // Skip Back Aggregation References
                if (metaField.Attributes.ContainsKey(McDataTypeAttribute.AggregationMark))
                    continue;
                //Skip referenses
                if (metaField.IsReference)
                    continue;

                // Process Aggregation
                if (metaField.IsAggregation)
                {
                    // Find Aggr meta class
                    MetaClass aggrMetaClass = DataContext.Current.GetMetaClass((string)metaField.Attributes[McDataTypeAttribute.AggregationMetaClassName]);
                    // Find rules
                    retVal = CreateMapingByFriendlyNameComparison(column, aggrMetaClass, metaField.Name + ".", retVal, builder);
                    continue;
                }

                //Получаем имя в русской локализации
                string enName = GetWebResourceString(metaField.FriendlyName, CultureInfo.GetCultureInfo("en-US"));

                //получаем имя в английской локализации
                string ruName = GetWebResourceString(metaField.FriendlyName, CultureInfo.GetCultureInfo("ru-RU"));
                //Find best match for pattern
                foreach(string searchPattern in new string[] { enName, ruName })
                {
                    if (column.ColumnName.Contains(searchPattern))
                    {
                        FieldMathResult newResult = new FieldMathResult(column.ColumnName, searchPattern, mappedFieldName);
                        if (retVal != null)
                        {
                            retVal = retVal.Weight < newResult.Weight ? retVal : newResult;
                        }
                        else
                        {
                            retVal = newResult;
                        }
                        break;
                    }
                }
            }

            return retVal;
        }
示例#6
0
        /// <summary>
        /// Creates the default name of the mapping by.
        /// </summary>
        private static FieldMathResult CreateMapingByFriendlyNameComparison(DataColumn column, MetaClass dstClass,
                                                                            string prefix, FieldMathResult prevMatchResult,
                                                                            MappingElementBuilder builder)
        {
            FieldMathResult retVal = prevMatchResult;

            foreach (MetaField metaField in dstClass.Fields)
            {
                string mappedFieldName = prefix + metaField.Name;
                // Skip always maped metaField
                if (builder.GetRuleByMetaField(mappedFieldName) != null)
                {
                    continue;
                }
                // Skip Back Aggregation References
                if (metaField.Attributes.ContainsKey(McDataTypeAttribute.AggregationMark))
                {
                    continue;
                }
                //Skip referenses
                if (metaField.IsReference)
                {
                    continue;
                }

                // Process Aggregation
                if (metaField.IsAggregation)
                {
                    // Find Aggr meta class
                    MetaClass aggrMetaClass = DataContext.Current.GetMetaClass((string)metaField.Attributes[McDataTypeAttribute.AggregationMetaClassName]);
                    // Find rules
                    retVal = CreateMapingByFriendlyNameComparison(column, aggrMetaClass, metaField.Name + ".", retVal, builder);
                    continue;
                }

                //Получаем имя в русской локализации
                string enName = GetWebResourceString(metaField.FriendlyName, CultureInfo.GetCultureInfo("en-US"));

                //получаем имя в английской локализации
                string ruName = GetWebResourceString(metaField.FriendlyName, CultureInfo.GetCultureInfo("ru-RU"));
                //Find best match for pattern
                foreach (string searchPattern in new string[] { enName, ruName })
                {
                    if (column.ColumnName.Contains(searchPattern))
                    {
                        FieldMathResult newResult = new FieldMathResult(column.ColumnName, searchPattern, mappedFieldName);
                        if (retVal != null)
                        {
                            retVal = retVal.Weight < newResult.Weight ? retVal : newResult;
                        }
                        else
                        {
                            retVal = newResult;
                        }
                        break;
                    }
                }
            }

            return(retVal);
        }
示例#7
0
        /// <summary>
        /// Handles the ItemDataBound event of the dgMapping control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridItemEventArgs"/> instance containing the event data.</param>
        void dgMapping_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            DropDownList ddi = (DropDownList)e.Item.FindControl("ddColumns");

            if (ddi != null)
            {
                string mfName = e.Item.Cells[0].Text;

                #region Commented  may be needed
                //string ownFieldName = mfName;
                //string aggrFieldName = String.Empty;
                //string aggrClassName = String.Empty;
                //MetaClass ownClass = MetaDataWrapper.GetMetaClassByName(_className);
                //MetaClass aggrClass = null;
                //MetaField ownField = null;
                //MetaField aggrField = null;
                //if (ownFieldName.Contains("."))
                //{
                //    string[] mas = ownFieldName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                //    ownFieldName = mas[0];
                //    aggrFieldName = mas[1];
                //    ownField = MetaDataWrapper.GetMetaFieldByName(ownClass, ownFieldName);
                //    aggrClassName = ownField.Attributes.GetValue<string>(McDataTypeAttribute.AggregationMetaClassName);
                //    aggrField = MetaDataWrapper.GetMetaFieldByName(aggrClassName, aggrFieldName);
                //}
                //else
                //    ownField = MetaDataWrapper.GetMetaFieldByName(ownClass, ownFieldName);
                #endregion

                _ir = (ImportRequest)ViewState["_ir"];

                MetaField             field = FormController.GetMetaField(_className, mfName);
                MappingElementBuilder meb   = new MappingElementBuilder(_ir.MappingDocument);
                MappingRule           mr    = meb.GetRuleByMetaField(mfName);

                ddi.Items.Clear();
                ddi.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.Common", "tNotSetValue").ToString(), "-1"));
                if (field.GetOriginalMetaType() != null)
                {
                    ddi.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.Common", "tDefaultValue").ToString(), "0"));
                }

                foreach (DataColumn dc in _ir.Data.Tables[0].Columns)
                {
                    ddi.Items.Add(new ListItem(dc.ColumnName, dc.ColumnName));
                }

                string val = "-1";
                if (mr != null)
                {
                    if (mr.RuleType == MappingRuleType.DefaultValue)
                    {
                        val = "0";
                    }
                    else if (mr.RuleType == MappingRuleType.CopyValue)
                    {
                        val = mr.ColumnName;
                    }
                }
                CHelper.SafeSelect(ddi, val);

                TextBox      txt = (TextBox)e.Item.FindControl("tbColumn");
                DropDownList dd  = (DropDownList)e.Item.FindControl("ddColumn");
                switch (val)
                {
                case "-1":                              //Not Set
                    txt.Visible = false;
                    dd.Visible  = false;
                    break;

                case "0":                               //Default Value
                    if (field.IsEnum)
                    {
                        dd.Visible  = true;
                        txt.Visible = false;
                        dd.Items.Clear();
                        MetaFieldType mft = field.GetMetaType();
                        foreach (MetaEnumItem mei in mft.EnumItems)
                        {
                            dd.Items.Add(new ListItem(CHelper.GetResFileString(mei.Name), mei.Handle.ToString()));
                        }
                        if (!String.IsNullOrEmpty(mr.DefaultValue))
                        {
                            CHelper.SafeSelect(dd, mr.DefaultValue);
                        }
                    }
                    else if (field.IsReference)
                    {
                        dd.Visible  = true;
                        txt.Visible = false;
                        dd.Items.Clear();
                        string         refClassName = field.Attributes.GetValue <string>(McDataTypeAttribute.ReferenceMetaClassName);
                        MetaClass      refClass     = MetaDataWrapper.GetMetaClassByName(refClassName);
                        EntityObject[] list         = BusinessManager.List(refClassName, (new FilterElementCollection()).ToArray());

                        dd.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.Common", "tNotSetValue").ToString(), "-1"));
                        foreach (EntityObject eo in list)
                        {
                            dd.Items.Add(new ListItem(CHelper.GetResFileString(eo[refClass.TitleFieldName].ToString()), eo.PrimaryKeyId.Value.ToString()));
                        }
                        if (!String.IsNullOrEmpty(mr.DefaultValue))
                        {
                            CHelper.SafeSelect(dd, mr.DefaultValue);
                        }
                    }
                    else
                    {
                        dd.Visible  = false;
                        txt.Visible = true;
                        txt.Text    = mr.DefaultValue;
                    }
                    break;

                default:                                //CopyValue
                    txt.Visible = false;
                    dd.Visible  = false;
                    break;
                }

                //Update UpdatePanel with lbl & txt && dd (upValues)
                foreach (Control c in e.Item.Cells[3].Controls)
                {
                    if (c is UpdatePanel)
                    {
                        ((UpdatePanel)c).Update();
                    }
                }
            }
        }
示例#8
0
        /// <summary>
        /// Gets the mapping source.
        /// </summary>
        /// <returns></returns>
        private DataTable GetMappingSource()
        {
            if (ViewState["_ir"] == null)
            {
                return(null);
            }
            _ir = (ImportRequest)ViewState["_ir"];

            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("metaFieldName", typeof(string)));
            dt.Columns.Add(new DataColumn("metaField", typeof(string)));
            dt.Columns.Add(new DataColumn("column", typeof(string)));
            DataRow dr;

            MetaClass             mc  = MetaDataWrapper.GetMetaClassByName(_className);
            MappingElementBuilder meb = new MappingElementBuilder(_ir.MappingDocument);

            foreach (MetaField mf in mc.Fields)
            {
                if (mf.InPrimaryKey || mf.IsBackReference || mf.IsLink || mf.IsReferencedField ||
                    !SchemaAttribute.CheckIsUpdatable(mf))
                {
                    continue;
                }

                if (mf.IsAggregation)
                {
                    #region IsAggregation
                    string    aggrClassName = mf.Attributes.GetValue <string>(McDataTypeAttribute.AggregationMetaClassName);
                    MetaClass aggrClass     = MetaDataWrapper.GetMetaClassByName(aggrClassName);
                    foreach (MetaField aggrField in aggrClass.Fields)
                    {
                        if (aggrField.InPrimaryKey || aggrField.IsBackReference || aggrField.IsLink ||
                            aggrField.IsReferencedField ||
                            !SchemaAttribute.CheckIsUpdatable(mf) ||
                            aggrField.Attributes.ContainsKey(McDataTypeAttribute.AggregationMark))
                        {
                            continue;
                        }

                        dr = dt.NewRow();
                        string uniqName = String.Format("{0}.{1}", mf.Name, aggrField.Name);
                        dr["metaFieldName"] = uniqName;
                        dr["metaField"]     = CHelper.GetResFileString(aggrField.FriendlyName) + " (" + ((aggrField.GetOriginalMetaType() == null) ? aggrField.TypeName : CHelper.GetResFileString(aggrField.GetMetaType().FriendlyName)) + ")";

                        MappingRule mr = meb.GetRuleByMetaField(uniqName);

                        if (mr != null)
                        {
                            dr["column"] = mr.ColumnName;
                        }
                        else
                        {
                            dr["column"] = String.Empty;
                        }
                        dt.Rows.Add(dr);
                    }
                    #endregion

                    continue;
                }

                #region NonAggregation
                dr = dt.NewRow();
                dr["metaFieldName"] = mf.Name;
                dr["metaField"]     = CHelper.GetResFileString(mf.FriendlyName) + " (" + ((mf.GetOriginalMetaType() == null) ? mf.TypeName : CHelper.GetResFileString(mf.GetMetaType().FriendlyName)) + ")";

                MappingRule mr1 = meb.GetRuleByMetaField(mf.Name);

                if (mr1 != null)
                {
                    dr["column"] = mr1.ColumnName;
                }
                else
                {
                    dr["column"] = String.Empty;
                }

                dt.Rows.Add(dr);
                #endregion
            }
            return(dt);
        }