public object Clone()
        {
            EPJoin obj = new EPJoin();

            obj.field1 = (EPField)field1.Clone();
            obj.field2 = (EPField)field2.Clone();
            return(obj);
        }
 private void dataGrid1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     if (editState != EnumEditState.Ready)
     {
         return;
     }
     editState = EnumEditState.ValueCellChanged;
     try
     {
         if (e.ColumnIndex == 1)
         {
             bool   b  = (bool)(dataGrid1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
             string fn = (string)(dataGrid1.Rows[e.RowIndex].Cells[0].Value);
             if (b)
             {
                 EPField f = objRet.GetField(fn);
                 if (f == null)
                 {
                     EPField f0 = _currentFields[fn];
                     if (f0 != null)
                     {
                         f = (EPField)f0.Clone();
                         objRet.AddField(f);
                     }
                 }
             }
             else
             {
                 objRet.RemoveField(fn);
             }
             objRet.SQL  = string.Empty;
             txtSQL.Text = objRet.SQL;
         }
         else if (e.ColumnIndex == 2)
         {
             string  fn  = (string)(dataGrid1.Rows[e.RowIndex].Cells[0].Value);
             string  val = (string)(dataGrid1.Rows[e.RowIndex].Cells[2].Value);
             EPField f   = objRet.GetField(fn);
             if (f != null)
             {
                 f.FieldText = val;
                 objRet.SQL  = string.Empty;
                 txtSQL.Text = objRet.SQL;
             }
         }
     }
     finally
     {
         editState = EnumEditState.Ready;
     }
 }
        /// <summary>
        /// replace parameters with ? and collect non-unique parameter names in paramMap
        /// </summary>
        /// <param name="sSQL">the SQL string to parse, it can be any part of SQL</param>
        /// <param name="paramList">for validation. parameter names must be in this list</param>
        /// <param name="paramMap">this list is filled with the non-unique parameter names</param>
        /// <returns>the SQL string with parameters replaced with ?</returns>
        public static string MapParameters(string sSQL, EnumParameterStyle paramStyle, string sepStart, string sepEnd, FieldList paramList, FieldList paramMap, ParameterList psOld)
        {
            if (sSQL == null)
            {
                sSQL = "";
            }
            string S = sSQL;

            if (S.Length > 0)
            {
                string  name;
                EPField fld;
                int     n = SQLParser.FindParameterIndex(S, 0, sepStart, sepEnd, out ParseError);
                while (n >= 0)
                {
                    int i = SQLParser.FindNameEnd(S, n);
                    name = S.Substring(n, i - n);
                    name = name.Trim();
                    if (paramStyle == EnumParameterStyle.QuestionMark)
                    {
                        S = string.Format(CultureInfo.InvariantCulture, "{0}? {1}", S.Substring(0, n), S.Substring(i));
                        n++;
                    }
                    else if (paramStyle == EnumParameterStyle.LeadingQuestionMark)
                    {
                        string pname = ParameterList.GetParameterName(paramStyle, name);
                        S  = string.Format(CultureInfo.InvariantCulture, "{0}{1} {2}", S.Substring(0, n), pname, S.Substring(i));
                        n += pname.Length + 1;
                    }
                    else
                    {
                        n += name.Length + 1;
                    }
                    fld = paramList[name];
                    if (fld == null)
                    {
                        EPField f0 = null;
                        if (psOld != null && psOld.Count > 0)
                        {
                            f0 = psOld[name];
                        }
                        if (f0 == null)
                        {
                            fld = new EPField(paramList.Count, name);
                        }
                        else
                        {
                            fld       = f0.Clone() as EPField;
                            fld.Index = paramList.Count;
                        }
                        paramList.Add(fld);
                    }
                    if (paramStyle == EnumParameterStyle.QuestionMark)
                    {
                        //non-unique name is added
                        paramMap.AddFieldDup(fld);
                    }
                    n = SQLParser.FindParameterIndex(S, n, sepStart, sepEnd, out ParseError);
                }
            }
            return(S);
        }
        void addFilter(bool asAND)
        {
            string s = txtWhere.Text.Trim();

            if (s.Length > 0)
            {
                if (asAND)
                {
                    s += " AND ";
                }
                else
                {
                    s += " OR ";
                }
            }
            bool   bOK  = false;
            string sMsg = "";

            if (lstOP.SelectedIndex < 0)
            {
                sMsg = Resource1.w3;
            }
            else
            {
                EPField fld0 = cbxField.SelectedItem as EPField;
                if (fld0 == null)
                {
                    sMsg = Resource1.w4;
                }
                else
                {
                    EPField fld = (EPField)fld0.Clone();
                    s += qParser.Sep1 + fld.FromTableName + qParser.Sep2 + "." + qParser.Sep1 + fld.Name + qParser.Sep2 + " ";
                    FilterOperator op = lstOP.Items[lstOP.SelectedIndex] as FilterOperator;
                    s += op.sOpStart;
                    s += " ";
                    if (op.StartOnly)
                    {
                        bOK = true;
                    }
                    else
                    {
                        string s2;
                        if (rdoField.Checked)
                        {
                            EPField fldVal = cbxValField.SelectedItem as EPField;
                            if (fldVal != null)
                            {
                                s  += qParser.Sep1 + fldVal.FromTableName + qParser.Sep2 + "." + qParser.Sep1 + fldVal.Name + qParser.Sep2;
                                bOK = true;
                            }
                            else
                            {
                                sMsg = Resource1.w5;
                            }
                        }
                        else if (rdoParam.Checked)
                        {
                            s2 = txtParam.Text.Trim();
                            if (s2.Length > 0)
                            {
                                fld.Name = "@" + s2;
                                s       += fld.Name;
                                if (qParser.parameters == null)
                                {
                                    qParser.parameters = new ParameterList();
                                }
                                qParser.parameters.AddField(fld);
                                bOK = true;
                            }
                            else
                            {
                                sMsg = Resource1.w6;
                            }
                        }
                        else if (rdoConst.Checked)
                        {
                            string sQuote = fld.ConstQuote(oldQuery.IsOleDb);
                            s2 = txtConst.Text.Trim();
                            if (s2.Length > 0)
                            {
                                s2  = s2.Replace("'", "''");
                                s  += sQuote;
                                s  += s2;
                                s  += sQuote;
                                bOK = true;
                            }
                            else
                            {
                                sMsg = Resource1.w7;
                            }
                        }
                    }
                    if (bOK)
                    {
                        s            += op.sOpEnd;
                        txtWhere.Text = s;
                    }
                }
            }
            if (sMsg.Length > 0)
            {
                MessageBox.Show(this, sMsg, this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop);
            }
        }
Exemplo n.º 5
0
 private void btOK_Click(object sender, System.EventArgs e)
 {
     try
     {
         bool   bOK = false;
         EPJoin J;
         join = new TableRelation();
         if (rdoInner.Checked)
         {
             join.Relation = enmTableRelation.INNER;
         }
         else if (radioButton1.Checked)
         {
             join.Relation = enmTableRelation.LEFT;
         }
         else
         {
             //no join
             join              = new TableRelation();
             join.Relation     = enmTableRelation.NONE;
             join.Table2       = lblTable.Text;
             this.DialogResult = System.Windows.Forms.DialogResult.OK;
             Close();
             return;
         }
         string     s;
         EPField    fld = null;
         TableAlias tbl;
         for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
         {
             bOK = false;
             J   = new EPJoin();
             s   = ds.Tables[0].Rows[i][0].ToString();
             if (s.Length > 0)
             {
                 if (srcType == enumRecSource.Table)
                 {
                     fld = newTable.FindField(s);
                 }
                 else if (srcType == enumRecSource.View)
                 {
                     fld = newView.FindField(s);
                 }
                 if (fld != null)
                 {
                     J.field2 = (EPField)fld.Clone();
                     J.field2.FromTableName = lblTable.Text;
                     s   = ds.Tables[0].Rows[i][1].ToString();
                     tbl = parser.query.T[s];
                     if (tbl != null)
                     {
                         s        = ds.Tables[0].Rows[i][2].ToString();
                         J.field1 = tbl.FindField(s);
                         if (J.field1 != null)
                         {
                             J.field1.FromTableName = tbl.TableName;
                             join.AddJoin(J);
                             bOK = true;
                         }
                     }
                 }
             }
             if (!bOK)
             {
                 break;
             }
         }
         if (!bOK)
         {
             MessageBox.Show(this, Resource1.addT3, this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop);
         }
         else if (join.FieldCount <= 0)
         {
             MessageBox.Show(this, Resource1.addT4, this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop);
         }
         else
         {
             this.DialogResult = System.Windows.Forms.DialogResult.OK;
             Close();
         }
     }
     catch (Exception er)
     {
         MessageBox.Show(this, er.Message, this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop);
     }
 }