private void buttonOK_Click(object sender, EventArgs e)
        {
            StringMapList maps = new StringMapList();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string val = ValueConvertor.ToString(ds.Tables[0].Rows[i][1]);
                if (!string.IsNullOrEmpty(val))
                {
                    maps.AddFieldMap(ValueConvertor.ToString(ds.Tables[0].Rows[i][0]), val);
                }
            }
            DataEditorLookupDB edb = this.SelectedEditor as DataEditorLookupDB;

            if (edb != null)
            {
                edb.valuesMaps.AdditionalJoins = maps;
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                WebDataEditorLookupDB wd = this.SelectedEditor as WebDataEditorLookupDB;
                if (wd != null)
                {
                    wd.FieldsMap      = maps;
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
        public override void SetEditorAttributes(DataEditor current)
        {
            DataEditorLookupDB ddb = current as DataEditorLookupDB;

            if (ddb != null)
            {
            }
        }
        protected override void OnClone(DataEditor cloned)
        {
            DataEditorLookupDB obj = cloned as DataEditorLookupDB;

            obj._qry = (EasyQuery)Query.Clone();
            if (valuesMaps != null)
            {
                obj.valuesMaps = (DataBind)valuesMaps.Clone();
            }
        }
        public static DlgSetEditorAttributes GetDatabaseLookupDataDialog(DataEditor current, DataEditor caller)
        {
            DataEditorLookupDB dbe0 = caller as DataEditorLookupDB;

            if (dbe0 != null)
            {
                DataEditorLookupDB dbe = current as DataEditorLookupDB;
                if (dbe == null)
                {
                    dbe = new DataEditorLookupDB();
                    dbe.valuesMaps.AdditionalJoins = dbe0.valuesMaps.AdditionalJoins;
                }
                else
                {
                    if (dbe0.valuesMaps.AdditionalJoins != null)
                    {
                        for (int i = 0; i < dbe0.valuesMaps.AdditionalJoins.Count; i++)
                        {
                            if (string.IsNullOrEmpty(dbe0.valuesMaps.AdditionalJoins[i].Source))
                            {
                                string val = dbe.valuesMaps.GetMappedField(dbe0.valuesMaps.AdditionalJoins[i].Target);
                                if (!string.IsNullOrEmpty(val))
                                {
                                    dbe0.valuesMaps.AdditionalJoins[i].Source = val;
                                }
                            }
                        }
                        dbe.valuesMaps.AdditionalJoins = dbe0.valuesMaps.AdditionalJoins;
                    }
                }
                return(new DlgDataEditDatabaseLookup(dbe));
            }
            else
            {
                WebDataEditorLookupDB wd0 = caller as WebDataEditorLookupDB;
                if (wd0 != null)
                {
                    WebDataEditorLookupDB wd = current as WebDataEditorLookupDB;
                    if (wd == null)
                    {
                        wd = (WebDataEditorLookupDB)wd0.Clone();
                    }
                    else
                    {
                        if (wd0.FieldsMap != null)
                        {
                            wd.FieldsMap = wd0.FieldsMap;
                        }
                    }
                    return(new DlgDataEditDatabaseLookup(wd));
                }
            }
            return(null);
        }
        void qry_SqlChanged(object sender, EventArgs e)
        {
            DataEditorLookupDB edb = (DataEditorLookupDB)(this.SelectedEditor);
            FieldList          fl  = edb.Query.Fields;

            objRet.SourceFields = new string[fl.Count];
            for (int i = 0; i < objRet.SourceFields.Length; i++)
            {
                objRet.SourceFields[i] = fl[i].Name;
            }
            loadFields();
        }
 public DlgDataEditDatabaseLookup(DataEditorLookupDB editor)
     : base(editor)
 {
     InitializeComponent();
     //
     if (editor == null)
     {
         editor = new DataEditorLookupDB();
         SetSelection(editor);
     }
     LoadData(editor.valuesMaps);
     if (editor.Query == null)
     {
         editor.Query = new EasyQuery();
     }
     editor.Query.SqlChanged     += new EventHandler(qry_SqlChanged);
     propertyGrid1.SelectedObject = editor.Query;
     editor.Query.SetLoaded();
 }
Exemplo n.º 7
0
 /// <summary>
 /// setup a database lookup for the field
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btLookup_Click(object sender, System.EventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         item = listView1.SelectedItems[0];
         if (item != null)
         {
             //build the query for the database lookup
             EasyQuery          qry = null;
             DataEditorLookupDB lk  = fields[item.Index].editor as DataEditorLookupDB;
             if (lk == null)
             {
                 lk = new DataEditorLookupDB();
             }
             if (lk.Query != null)
             {
                 qry = lk.Query;
             }
             if (qry == null)
             {
                 qry = new EasyQuery();
             }
             //edit the query
             EasyQuery q = EasyQuery.Edit(qry, this);
             if (q != null)
             {
                 lk.Query = q;
                 fields[item.Index].editor = lk;
                 txtLookup.Text            = lk.ToString();
                 FieldList srcfields = lk.Query.Fields;                         //lookup fields provides the source fields
                 if (srcfields != null && srcfields.Count > 0)
                 {
                     if (ownerPerformer == null || srcfields.Count == 1)
                     {
                         //choose the field name that the value of this source field will map to
                         dlgSelectString dlg = new dlgSelectString();
                         for (int i = 0; i < fields.Count; i++)
                         {
                             dlg.LoadData(fields[i].Name);
                         }
                         dlg.Text = "Select field to update";
                         dlg.SetSel(lk.ValueField);
                         if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                         {
                             lk.ValueField = dlg.sRet;
                         }
                     }
                     else
                     {
                         if (lk.valuesMaps == null)
                         {
                             lk.valuesMaps = new DataBind();
                         }
                         lk.valuesMaps.SourceFields = new string[srcfields.Count];
                         for (int i = 0; i < srcfields.Count; i++)
                         {
                             lk.valuesMaps.SourceFields[i] = srcfields[i].Name;
                         }
                         dlgPropDataLink dlg2 = new dlgPropDataLink();
                         dlg2.LoadData(lk.valuesMaps);
                     }
                 }
             }
         }
     }
 }
        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);
                    }
                }
            }
        }