public virtual object Clone()
        {
            DataBind obj = new DataBind();

            if (AdditionalJoins != null)
            {
                obj.AdditionalJoins = (StringMapList)AdditionalJoins.Clone();
            }
            if (SourceFields != null)
            {
                obj.SourceFields = new string[SourceFields.Length];
                for (int i = 0; i < SourceFields.Length; i++)
                {
                    obj.SourceFields[i] = SourceFields[i];
                }
            }
            return(obj);
        }
        public void LoadData(DataBind dbd)
        {
            const string TABLENAME = "Links";

            objRet = dbd;
            //
            ds.Tables.Clear();
            ds.Tables.Add(TABLENAME);
            //
            ds.Tables[0].Columns.Add();
            ds.Tables[0].Columns.Add();
            //
            ds.Tables[0].Columns[0].Caption    = "Fields to be Updated";
            ds.Tables[0].Columns[0].ColumnName = "Destination";
            ds.Tables[0].Columns[0].DataType   = typeof(string);
            ds.Tables[0].Columns[0].MaxLength  = 120;
            ds.Tables[0].Columns[0].ReadOnly   = true;
            //
            ds.Tables[0].Columns[1].Caption    = "Source Fields";
            ds.Tables[0].Columns[1].ColumnName = "Source";
            ds.Tables[0].Columns[1].DataType   = typeof(string);
            ds.Tables[0].Columns[1].MaxLength  = 120;
            //
            //
            dataGridView1.DataSource              = ds;
            dataGridView1.DataMember              = TABLENAME;
            dataGridView1.ReadOnly                = true;
            dataGridView1.AllowUserToAddRows      = false;
            dataGridView1.AllowUserToDeleteRows   = false;
            dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            //
            cbx2         = new System.Windows.Forms.ComboBox();
            cbx2.Parent  = dataGridView1;
            cbx2.Visible = false;
            cbx2.Left    = 0;
            cbx2.SelectedIndexChanged += new EventHandler(cbx2_SelectedIndexChanged);
            //
            loadFields();
        }
Exemple #3
0
        public void LoadData(DataBind dbd)
        {
            objRet = dbd;
            //
            ds.Tables.Clear();
            ds.Tables.Add("Links");
            //
            ds.Tables[0].Columns.Add();
            ds.Tables[0].Columns.Add();
            //
            ds.Tables[0].Columns[0].Caption    = "Fields to be Updated";
            ds.Tables[0].Columns[0].ColumnName = "Destination";
            ds.Tables[0].Columns[0].DataType   = typeof(string);
            ds.Tables[0].Columns[0].MaxLength  = 120;
            ds.Tables[0].Columns[0].ReadOnly   = true;
            //
            ds.Tables[0].Columns[1].Caption    = "Source Fields";
            ds.Tables[0].Columns[1].ColumnName = "Source";
            ds.Tables[0].Columns[1].DataType   = typeof(string);
            ds.Tables[0].Columns[1].MaxLength  = 120;
            //			ds.Tables[0].Columns[1].ReadOnly = true;
            //
            DataGridColumnStyle TextCol;
            DataGridTableStyle  myGridTableStyle = new DataGridTableStyle();

            myGridTableStyle.MappingName = "Links";
            //
            TextCol             = new DataGridTextBoxColumn();
            TextCol.MappingName = ds.Tables[0].Columns[0].ColumnName;
            TextCol.HeaderText  = ds.Tables[0].Columns[0].Caption;
            TextCol.Width       = 160;
            myGridTableStyle.GridColumnStyles.Add(TextCol);
            //
            TextCol             = new DataGridTextBoxColumn();
            TextCol.MappingName = ds.Tables[0].Columns[1].ColumnName;
            TextCol.HeaderText  = ds.Tables[0].Columns[1].Caption;
            TextCol.Width       = 160;
            myGridTableStyle.GridColumnStyles.Add(TextCol);
            //
            dataGrid1.TableStyles.Clear();
            dataGrid1.TableStyles.Add(myGridTableStyle);
            //
            dataGrid1.SetDataBinding(ds, "Links");
            dataGrid1.ReadOnly = true;
            //
            int i;
            int n = objRet.SourceFieldCount;

            if (n == 0)
            {
                MessageBox.Show("Linked data source not found (SourceFieldCount = 0)");
                return;
            }
            cbx2         = new System.Windows.Forms.ComboBox();
            cbx2.Parent  = dataGrid1;
            cbx2.Visible = false;
            cbx2.Left    = 0;
            cbx2.SelectedIndexChanged += new EventHandler(cbx2_SelectedIndexChanged);
            cbx2.Items.Add("");
            for (i = 0; i < n; i++)
            {
                cbx2.Items.Add(objRet.SourceFields[i]);
            }
            object[] vs;
            for (i = 0; i < n; i++)
            {
                vs    = new object[2];
                vs[0] = objRet.SourceFields[i];                        // flds[i].Name; //field to be updated
                vs[1] = objRet.GetMappedField(objRet.SourceFields[i]); //source field
                ds.Tables[0].Rows.Add(vs);
            }
        }
        void onLookupSelected(object sender, System.EventArgs e)
        {
//			int xx= 0;

            ComboLook cb = (ComboLook)sender;

            if (cb.bNoEvent)
            {
                return;
            }
            int n = cb.SelectedIndex;

            if (n >= 0)
            {
                object Value = cb.GetLookupData();
                if (currentCellInSynch())
                {
                    bool bMatch = false;
                    if (cbx != null && nCurrentCellColumn >= 0 && nCurrentCellColumn < cbx.Length)
                    {
                        bMatch = (cbx[nCurrentCellColumn] == sender);
                    }
                    try
                    {
                        System.Data.DataRow dw = CurrentRow;
                        if (bMatch && dw != null && _query.Fields[nCurrentCellColumn].editor != null)
                        {
                            DataBind           databind = null;
                            DataEditorLookupDB lk       = _query.Fields[nCurrentCellColumn].editor as DataEditorLookupDB;
                            if (lk != null)
                            {
                                databind = lk.valuesMaps;
                            }
                            DataRow rv = Value as DataRow;
                            if (databind != null && rv != null)
                            {
                                if (databind.AdditionalJoins != null && databind.AdditionalJoins.StringMaps != null)
                                {
                                    for (int i = 0; i < databind.AdditionalJoins.StringMaps.Length; i++)
                                    {
                                        dw[databind.AdditionalJoins.StringMaps[i].Field1] = rv[databind.AdditionalJoins.StringMaps[i].Field2];
                                    }
                                }
                                onLookup();
                            }
                            else
                            {
                                if (rv != null)
                                {
                                    Value = rv[1];
                                }
                                bool bEQ  = false;
                                int  nPos = cb.GetUpdateFieldIndex();
                                if (nPos < 0)
                                {
                                    nPos = nCurrentCellColumn;
                                }
                                if (Value == null)
                                {
                                    if (dw[nPos] == null)
                                    {
                                        bEQ = true;
                                    }
                                }
                                else if (Value == System.DBNull.Value)
                                {
                                    bEQ = (dw[nPos] == System.DBNull.Value);
                                }
                                else if (Value.Equals(dw[nPos]))
                                {
                                    bEQ = true;
                                }
                                if (!bEQ)
                                {
                                    dw.BeginEdit();
                                    dw[nPos] = Value;
                                    dw.EndEdit();
                                    dw[nCurrentCellColumn] = ValueConvertor.ToObject(cb.Text, _query.Tables[0].Columns[nCurrentCellColumn].DataType);
                                }
                                //							if(xx>=0)
                                //								return;
                                //							bNoEvents = true;
                                //							cb.Visible = false;
                                //							bNoEvents = false;
                                //							onRowIndexChanged();

                                if (!bEQ)
                                {
                                    onLookup();
                                }
                            }
                        }
                    }
                    catch (Exception er)
                    {
                        FormLog.NotifyException(er);
                    }
                }
            }
        }