private void AutoFillFields()
        {
            Mapping_rep x = (Mapping_rep)mapsBindingSource.Current;
            //IDataSource ds = DMEEditor.GetDataSource(x.Entity2DataSource);

            List <DefaultValue> defaults = DMEEditor.ConfigEditor.DataConnections[DMEEditor.ConfigEditor.DataConnections.FindIndex(i => i.ConnectionName == x.Entity2DataSource)].DatasourceDefaults;

            fldMappingBindingSource.Clear();
            foreach (EntityField s in x.Entity2Fields.OrderBy(p => p.FieldIndex))
            {
                fldMappingBindingSource.AddNew();
                Mapping_rep_fields T = T = (Mapping_rep_fields)fldMappingBindingSource.Current;
                if (FieldExist(s.fieldname, x.Entity1Fields))
                {
                    T.FieldName1 = s.fieldname;
                    T.FieldName2 = s.fieldname;
                    T.FieldType1 = s.fieldtype;
                    T.FieldType2 = s.fieldtype;
                }
                else
                {
                    T.FieldName2 = s.fieldname;
                    T.FieldType2 = s.fieldtype;
                }
                if (defaults != null)
                {
                    if (defaults.Any(u => u.propertyName.ToLower() == s.fieldname.ToLower() && u.propertyType != DefaultValueType.DisplayLookup))
                    {
                        string df = defaults.Where(u => u.propertyName.ToLower() == s.fieldname.ToLower() && u.propertyType != DefaultValueType.DisplayLookup).FirstOrDefault().propertyName;
                        T.Rules = $":Default.{df}";
                    }
                }
            }
        }
        private void EntityName1ComboBox_SelectedValueChanged(object sender, EventArgs e)
        {
            if (mapsBindingSource.Count > 0)
            {
                Mapping_rep x = (Mapping_rep)mapsBindingSource.Current;
                if (!string.IsNullOrEmpty(x.EntityName1))
                {
                    if (ds1 != null)
                    {
                        if (ds1.Entities.Count == 0 || !ds1.Entities.Any(i => i.EntityName == x.EntityName1))
                        {
                            x.Entity1Fields = ds1.GetEntityStructure(x.EntityName1, false).Fields;
                            DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities {
                                datasourcename = ds1.DatasourceName, Entities = ds1.Entities
                            });
                        }
                        else
                        {
                            x.Entity1Fields = ds1.Entities.Where(i => i.EntityName == x.EntityName1).FirstOrDefault().Fields;
                        }
                    }


                    fieldName1ComboBox.Items.Clear();

                    foreach (EntityField s in x.Entity1Fields)
                    {
                        fieldName1ComboBox.Items.Add(s.fieldname);
                    }
                }
            }
        }
        private void CreateDataSources()
        {
            Mapping_rep x = (Mapping_rep)mappingsBindingSource.Current;

            ds1 = DMEEditor.GetDataSource(x.Entity1DataSource);

            ds2 = DMEEditor.GetDataSource(x.Entity2DataSource);
        }
        private void FldMappingBindingSource_AddingNew(object sender, AddingNewEventArgs e)
        {
            Mapping_rep_fields x = new Mapping_rep_fields();
            Mapping_rep        y = (Mapping_rep)mappingsBindingSource.Current;

            x.EntityName1 = y.EntityName1;
            x.EntityName2 = y.EntityName2;
            e.NewObject   = x;
        }
 private void SyncMappingbutton_Click(object sender, EventArgs e)
 {
     if (mappingsBindingSource.Count > 0)
     {
         Mapping_rep x = (Mapping_rep)mappingsBindingSource.Current;
         if (x.EntityName1 != null && x.EntityName2 != null && x.Entity1DataSource != null && x.Entity2DataSource != null)
         {
             SyncFields();
         }
     }
 }
 private void CreateMappingbutton_Click(object sender, EventArgs e)
 {
     if (mappingsBindingSource.Count > 0)
     {
         Mapping_rep x = (Mapping_rep)mappingsBindingSource.Current;
         if (x.EntityName1 != null && x.EntityName2 != null && x.Entity1DataSource != null && x.Entity2DataSource != null)
         {
             GetFieldTypes();
             CreateFieldMappingCombo();
         }
     }
 }
        private void GetFieldTypes()
        {
            if (mappingsBindingSource.Count > 0)
            {
                Mapping_rep x = (Mapping_rep)mappingsBindingSource.Current;
                if (ds1 != null)
                {
                    x.Entity1Fields = ds1.GetEntityStructure(x.EntityName1, false).Fields;
                }

                if (ds2 != null)
                {
                    x.Entity2Fields = ds2.GetEntityStructure(x.EntityName2, false).Fields;
                }
            }
            DMEEditor.ConfigEditor.SaveDataconnectionsValues();
        }
        private void CreateFieldMappingCombo()
        {
            FieldName1Comobobox.Items.Clear();
            FieldName2Comobobox.Items.Clear();
            if (mappingsBindingSource.Count > 0)
            {
                Mapping_rep x = (Mapping_rep)mappingsBindingSource.Current;

                foreach (EntityField s in x.Entity1Fields)
                {
                    FieldName1Comobobox.Items.Add(s.fieldname);
                }
                foreach (EntityField s in x.Entity2Fields)
                {
                    FieldName2Comobobox.Items.Add(s.fieldname);
                }
            }
        }
        private void AutoFillDestDatasource()
        {
            if (this.mapsBindingSource.Count > 0)
            {
                if (this.DestDatasourelistBox.SelectedItem != null)
                {
                    ConnectionProperties o = (ConnectionProperties)DestDatasourelistBox.SelectedItem;
                    mapsBindingSource.MoveFirst();
                    for (int i = 0; i < mapsBindingSource.Count; i++)
                    {
                        Mapping_rep m = (Mapping_rep)mapsBindingSource.Current;
                        m.Entity2DataSource = o.ConnectionName;

                        mapsBindingSource.MoveNext();
                    }
                }
            }
        }
        private void SyncFields()
        {
            fldMappingBindingSource.Clear();

            Mapping_rep x = (Mapping_rep)mappingsBindingSource.Current;

            foreach (EntityField s in x.Entity1Fields)
            {
                if (FieldExist(s.fieldname, x.Entity2Fields))
                {
                    fldMappingBindingSource.AddNew();
                    Mapping_rep_fields T = (Mapping_rep_fields)fldMappingBindingSource.Current;
                    T.FieldName1 = s.fieldname;
                    T.FieldName2 = s.fieldname;
                    T.FieldType1 = s.fieldtype;
                    T.FieldType2 = s.fieldtype;
                }
            }
        }
        private void FillData()
        {
            Mapping_rep m = (Mapping_rep)mapsBindingSource.Current;

            if (m != null)
            {
                if (this.fldMappingBindingSource.Count > 0)
                {
                    if (MessageBox.Show("Would you like to overwrite the existing mapping", "Mapping", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        AutoFillFields();
                    }
                }
                else
                {
                    AutoFillFields();
                }
            }
        }
 private void Savebutton_Click(object sender, EventArgs e)
 {
     try
     {
         mappingsBindingSource.EndEdit();
         Mapping_rep x = (Mapping_rep)mappingsBindingSource.Current;
         if (x.MappingName != null && x.EntityName1 != null && x.EntityName2 != null && x.Entity1DataSource != null && x.Entity2DataSource != null)
         {
             CleanMapping();
             // DMEEditor.ConfigEditor.Mappings = DMEEditor.WorkFlowEditor.Mappings;
             DMEEditor.ConfigEditor.SaveMappingValues();
         }
         else
         {
             MessageBox.Show("Please Complete all data fields before save");
         }
     }
     catch (Exception ex)
     {
         ErrorObject.Flag = Errors.Failed;
         ErrorObject.Ex   = ex;
         Logger.WriteLog($"Error in getting File Data ({ex.Message}) ");
     }
 }
        private void MappingsBindingSource_AddingNew(object sender, AddingNewEventArgs e)
        {
            Mapping_rep x = new Mapping_rep();

            e.NewObject = x;
        }
        private void MappingsDataGridView_DragDrop(object sender, DragEventArgs e)
        {
            Mapping_rep     x       = null;
            DataGridViewRow dragRow = null;

            if (e.Data.GetData("System.String").ToString() == "SOURCE")
            {
                if (SrcDataSourcelistBox1.SelectedItems.Count > 1)
                {
                    foreach (string item in SrcDataSourcelistBox1.SelectedItems)
                    {
                        x = new Mapping_rep();
                        x.Entity1DataSource = item;
                        x.MappingName       = $"From_{item}";
                        this.mapsBindingSource.Add(x);
                    }
                }
                else
                {
                    if (SrcDataSourcelistBox1.SelectedItems.Count == 1)
                    {
                        if (this.mapsBindingSource.Count == 0)
                        {
                            this.mapsBindingSource.AddNew();
                        }
                        string o = (string)SrcDataSourcelistBox1.SelectedItem;
                        x = (Mapping_rep)this.mapsBindingSource.Current;
                        x.Entity1DataSource = o;
                        x.MappingName       = $"From_{ o}";
                    }
                }
            }
            else
            {
                if (DestDatasourelistBox.SelectedItems.Count == 1)
                {
                    if (this.mapsBindingSource.Count == 0)
                    {
                        this.mapsBindingSource.AddNew();
                    }

                    Point p         = mappingsDataGridView.PointToClient(new Point(e.X, e.Y));
                    int   dragIndex = mappingsDataGridView.HitTest(p.X, p.Y).RowIndex;
                    // Determine if dragindex is valid row index
                    if (dragIndex > -1)
                    {
                        dragRow = (DataGridViewRow)mappingsDataGridView.Rows[dragIndex];
                    }
                    else
                    {
                    }     // Do any message here if selected in column header and blank space.


                    string o = (string)DestDatasourelistBox.SelectedItem;

                    x = (Mapping_rep)dragRow.DataBoundItem;
                    x.Entity2DataSource = o;
                    x.MappingName       = x.MappingName + $"_TO_{ o}";
                }
            }

            this.mappingsDataGridView.Refresh();
        }