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;
                }
            }
        }
 private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridView1.CurrentCell.RowIndex >= 0)
     {
         if (dataGridView1.CurrentCell.ColumnIndex == 1)
         {
             System.Drawing.Rectangle rc = dataGridView1.GetCellDisplayRectangle(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex, true);
             cbx2.SetBounds(rc.Left, rc.Top, rc.Width, rc.Height);
             cbx2.SelectedIndex = -1;
             if (dataGridView1.CurrentCell.RowIndex < ds.Tables[0].Rows.Count)
             {
                 string s = ValueConvertor.ToString(ds.Tables[0].Rows[dataGridView1.CurrentCell.RowIndex][dataGridView1.CurrentCell.ColumnIndex]);
                 for (int i = 0; i < cbx2.Items.Count; i++)
                 {
                     if (string.CompareOrdinal(ValueConvertor.ToString(cbx2.Items[i]), s) == 0)
                     {
                         cbx2.SelectedIndex = i;
                         break;
                     }
                 }
             }
             cbx2.Visible = true;
             cbx2.BringToFront();
         }
     }
 }
        public void AddDateParam(string name, System.DateTime dt)
        {
            DbParameter pam = cmd.CreateParameter();

            pam.ParameterName = name;
            pam.Size          = 8;
            pam.DbType        = ValueConvertor.OleDbTypeToDbType(System.Data.OleDb.OleDbType.DBTimeStamp);
            pam.Value         = dt;
            cmd.Parameters.Add(pam);
        }
        public void AddCommandParameter(EPField p, EnumParameterStyle style)
        {
            DbParameter pam = cmd.CreateParameter();

            pam.ParameterName = p.GetParameterNameForCommand(style);
            pam.DbType        = ValueConvertor.OleDbTypeToDbType(p.OleDbType);
            pam.Size          = p.DataSize;
            pam.Value         = p.Value;
            cmd.Parameters.Add(pam);
        }
 public void MakeCommand(string table, FieldList rowID, Connection cn)
 {
     if (fields.Count > 0)
     {
         int i;
         rowIDFields = rowID;
         //================================
         cmdUpdates = new DbCommand[fields.Count];
         for (int k = 0; k < fields.Count; k++)
         {
             cmdUpdates[k] = cn.CreateCommand();
             StringBuilder sSQL = new StringBuilder();
             sSQL.Append(QueryParser.SQL_Update());
             sSQL.Append(DatabaseEditUtil.SepBegin(cn.NameDelimiterStyle));
             sSQL.Append(table);
             sSQL.Append(DatabaseEditUtil.SepEnd(cn.NameDelimiterStyle));
             sSQL.Append(QueryParser.SQL_Set());
             sSQL.Append(DatabaseEditUtil.SepBegin(cn.NameDelimiterStyle));
             sSQL.Append(fields[k].Name);
             sSQL.Append(DatabaseEditUtil.SepEnd(cn.NameDelimiterStyle));
             sSQL.Append("=?");
             sSQL.Append(QueryParser.SQL_Where());
             sSQL.Append(DatabaseEditUtil.SepBegin(cn.NameDelimiterStyle));
             sSQL.Append(rowIDFields[0].Name);
             sSQL.Append(DatabaseEditUtil.SepEnd(cn.NameDelimiterStyle));
             sSQL.Append("=? ");
             for (i = 1; i < rowIDFields.Count; i++)
             {
                 sSQL.Append(QueryParser.SQL_And());
                 sSQL.Append(DatabaseEditUtil.SepBegin(cn.NameDelimiterStyle));
                 sSQL.Append(rowIDFields[i].Name);
                 sSQL.Append(DatabaseEditUtil.SepEnd(cn.NameDelimiterStyle));
                 sSQL.Append("=?");
             }
             cmdUpdates[k].CommandText = sSQL.ToString();
             DbParameter pam = cmdUpdates[k].CreateParameter();
             pam.ParameterName = fields[k].Name;
             pam.DbType        = ValueConvertor.OleDbTypeToDbType(fields[k].OleDbType);
             pam.Size          = fields[k].DataSize;
             pam.SourceColumn  = fields[k].Name;
             cmdUpdates[k].Parameters.Add(pam);
             for (i = 0; i < rowIDFields.Count; i++)
             {
                 pam = cmdUpdates[k].CreateParameter();
                 pam.ParameterName = rowIDFields[i].Name;
                 pam.DbType        = ValueConvertor.OleDbTypeToDbType(rowIDFields[i].OleDbType);
                 pam.Size          = rowIDFields[i].DataSize;
                 pam.SourceColumn  = rowIDFields[i].Name;
                 cmdUpdates[k].Parameters.Add(pam);
             }
         }
     }
 }
示例#6
0
        private void btOK_Click(object sender, System.EventArgs e)
        {
            string s1, s2;

            objRet.ClearFieldMaps();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                s2 = ValueConvertor.ToString(ds.Tables[0].Rows[i][1]);
                if (s2.Length > 0)
                {
                    s1 = ValueConvertor.ToString(ds.Tables[0].Rows[i][0]);
                    objRet.AddFieldMap(s1, s2);
                }
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }
 void onButtonClick(object sender, System.EventArgs e)
 {
     if (UseLargeDialogue)
     {
         dlgSelectDateTime dlg = new dlgSelectDateTime();
         System.DateTime   dt  = ValueConvertor.ToDateTime(currentValue);
         dlg.LoadData(dt);
         if (dlg.ShowDialog(OwnerForm) == DialogResult.OK)
         {
             FirePickValue(dlg.dRet);
         }
     }
     else
     {
         dlgSelectDateTimeSmall dlg = new dlgSelectDateTimeSmall();
         System.DateTime        dt  = ValueConvertor.ToDateTime(currentValue);
         dlg.LoadData(dt);
         if (dlg.ShowDialog(OwnerForm) == DialogResult.OK)
         {
             FirePickValue(dlg.dRet);
         }
     }
 }
        public virtual string Execute()
        {
            string sMsg = string.Empty;

            SetError(sMsg);
            _affectedRows = 0;
            if (_sql != null && connect != null)
            {
                DbCommand cmd = connect.ConnectionObject.CreateCommand();
                if (_transaction != null)
                {
                    cmd.Transaction = _transaction;
                }
                bool bClosed = !connect.ConnectionObject.Opened;
                if (bClosed)
                {
                    connect.ConnectionObject.Open();
                }
                if (connect.ConnectionObject.Opened)
                {
                    try
                    {
                        int i;
                        EnumParameterStyle pstyle = connect.ParameterStyle;
                        FieldList          pmMap  = new FieldList();
                        string             s;
                        int nCount;
                        s = _sql.GetSQLStatement(pmMap, pstyle);
                        if (pstyle == EnumParameterStyle.QuestionMark)
                        {
                            nCount = pmMap.Count;
                        }
                        else
                        {
                            nCount = _sql.ParamCount;
                        }
                        connect.Log("Command:{0}, params:{1}", s, nCount);
                        cmd.CommandText = s;
                        cmd.CommandType = CommandType.Text;
                        for (i = 0; i < nCount; i++)
                        {
                            DbParameter pam = cmd.CreateParameter();
                            EPField     f;
                            if (pstyle == EnumParameterStyle.QuestionMark)
                            {
                                f = pmMap[i];
                                pam.ParameterName = "@P" + i.ToString();
                            }
                            else
                            {
                                f = _sql.Parameters[i];
                                pam.ParameterName = ParameterList.GetParameterName(pstyle, _sql.Parameters[i].Name);
                            }
                            pam.DbType = ValueConvertor.OleDbTypeToDbType(f.OleDbType);
                            pam.Size   = f.DataSize;

                            OleDbParameter op = pam as OleDbParameter;
                            if (op != null && f.OleDbType == OleDbType.DBTimeStamp)
                            {
                                if (f.Value != null && f.Value != DBNull.Value)
                                {
                                    DateTime dt = (DateTime)(f.Value);
                                    dt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
                                    f.SetValue(dt);
                                }
                            }
                            connect.Log("param{0}:{1},{2},{3}. Value type:{4}. Value:{5}", i, pam.ParameterName, pam.DbType, pam.Size, f.OleDbType, f.Value);
                            if (EPField.IsDatetime(f.OleDbType))
                            {
                                if (f.IsNullOrEmpty)
                                {
                                    pam.Value = System.DBNull.Value;
                                }
                                else
                                {
                                    object dt0 = ValueConvertor.ConvertByOleDbType(f.Value, f.OleDbType);
                                    try
                                    {
                                        DateTime dt = (DateTime)dt0;
                                        if (dt.Ticks == 0)
                                        {
                                            pam.Value = System.DBNull.Value;
                                        }
                                        else
                                        {
                                            pam.Value = dt;
                                        }
                                    }
                                    catch
                                    {
                                        pam.Value = dt0;
                                    }
                                }
                            }
                            else
                            {
                                pam.Value = ValueConvertor.ConvertByOleDbType(f.Value, f.OleDbType);
                            }
                            cmd.Parameters.Add(pam);
                        }
                        _affectedRows = cmd.ExecuteNonQuery();
                        connect.Log("Affected rows:{0}", _affectedRows);
                        if (bClosed)
                        {
                            closeConnections();
                        }
                        if (this.ExecuteFinish != null)
                        {
                            ExecuteFinish(this, EventArgs.Empty);
                        }
                        if (_webPage != null && !string.IsNullOrEmpty(_name))
                        {
                            _webPage.SetServerComponentName(_name);
                        }
                    }
                    catch (Exception er)
                    {
                        if (_transaction != null)
                        {
                            _transaction.Rollback();
                            _transaction.Dispose();
                            _transaction = null;
                            connect.Log("rollback with error {0}", er.Message);
                            throw;
                        }
                        else
                        {
                            sMsg = ExceptionLimnorDatabase.FormExceptionText(er);
                        }
                    }
                    finally
                    {
                        if (bClosed)
                        {
                            if (connect.ConnectionObject.State != ConnectionState.Closed)
                            {
                                connect.ConnectionObject.Close();
                            }
                        }
                    }
                }
                else
                {
                    sMsg = "Database connection not set";
                }
            }
            else
            {
                sMsg = "SQL statement not set";
            }
            if (!string.IsNullOrEmpty(sMsg))
            {
                SetError(sMsg);
                if (connect != null)
                {
                    connect.Log("Error executing EasyUpdator.Execute. {0}", sMsg);
                }
            }
            return(sMsg);
        }
        public void CreateActionPhpScript(string objectName, string methodName, StringCollection code, StringCollection parameters, string returnReceiver)
        {
            string connName = GetConnectionCodeName();

            if (string.CompareOrdinal(methodName, "ExecuteWithParameterValues") == 0)
            {
                if (_sql != null && connect != null)
                {
                    code.Add("$GLOBALS[\"debugError\"] = '';\r\n");
                    code.Add("$msql = new JsonSourceMySql();\r\n");
                    code.Add(string.Format(CultureInfo.InvariantCulture, "$msql->SetCredential($this->{0});\r\n", connName));
                    code.Add("$msql->SetDebug($this->DEBUG);\r\n");
                    //
                    string        sql;
                    string[]      sqlParams;
                    List <string> inputParams  = new List <string>();
                    List <string> outputParams = new List <string>();
                    if (this.IsStoredProc)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("call ");
                        sb.Append(_sql.SQL);
                        sb.Append("(");
                        DatabaseExecuter de = this as DatabaseExecuter;
                        DbParameterList  ps = de.Parameters;
                        if (ps != null && ps.Count > 0)
                        {
                            ParameterDirection[] pds = de.Param_Directions;
                            for (int i = 0; i < ps.Count; i++)
                            {
                                if (i > 0)
                                {
                                    sb.Append(",");
                                }
                                ParameterDirection pd = ParameterDirection.Input;
                                if (pds != null && pds.Length > i)
                                {
                                    pd = pds[i];
                                }
                                switch (pd)
                                {
                                case ParameterDirection.Input:
                                    inputParams.Add(ps[i].Name);
                                    sb.Append(" ? ");
                                    break;

                                case ParameterDirection.InputOutput:
                                    outputParams.Add(ps[i].Name);
                                    sb.Append(string.Format(CultureInfo.InvariantCulture, " @{0} ", ps[i].Name));
                                    break;

                                case ParameterDirection.Output:
                                    outputParams.Add(ps[i].Name);
                                    sb.Append(string.Format(CultureInfo.InvariantCulture, " @{0} ", ps[i].Name));
                                    break;
                                }
                            }
                            sqlParams = inputParams.ToArray();
                        }
                        else
                        {
                            sqlParams = new string[] { };
                        }
                        sb.Append(")");
                        sql = sb.ToString();
                    }
                    else
                    {
                        sql       = _sql.SQL;
                        sqlParams = EasyQuery.GetParameterNames(sql, connect.NameDelimiterBegin, connect.NameDelimiterEnd);
                        if (sqlParams != null)
                        {
                            for (int i = 0; i < sqlParams.Length; i++)
                            {
                                sql = sql.Replace(sqlParams[i], "?");
                            }
                        }
                    }
                    code.Add(string.Format(CultureInfo.InvariantCulture, "$sql = \"{0} \";\r\n", sql));
                    code.Add("$ps = array();\r\n");
                    if (this.Parameters != null)
                    {
                        for (int i = 0; i < sqlParams.Length; i++)
                        {
                            int k = this.Parameters.GetIndex(sqlParams[i]);
                            if (k < 0)
                            {
                                throw new ExceptionLimnorDatabase("Query Parameter [{0}] not found", sqlParams[i]);
                            }
                            DbCommandParam dp = this.Parameters[k];
                            code.Add("$p = new SqlClientParameter();\r\n");
                            code.Add(string.Format(CultureInfo.InvariantCulture, "$p->name = '{0}';\r\n", dp.Name));
                            code.Add(string.Format(CultureInfo.InvariantCulture, "$p->type = '{0}';\r\n", ValueConvertor.OleDbTypeToPhpMySqlType(dp.Type)));
                            code.Add(string.Format(CultureInfo.InvariantCulture, "$p->value = {0};\r\n", parameters[k]));
                            code.Add("$ps[] = $p;\r\n//\r\n");
                        }
                    }
                    if (outputParams.Count > 0)
                    {
                        StringBuilder sb2 = new StringBuilder();
                        sb2.Append("SELECT ");
                        for (int i = 0; i < outputParams.Count; i++)
                        {
                            if (i > 0)
                            {
                                sb2.Append(",");
                            }
                            sb2.Append(string.Format(CultureInfo.InvariantCulture, "@{0} AS {0} ", outputParams[i]));
                        }
                        string s2 = string.Format(CultureInfo.InvariantCulture, "$qry{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
                        code.Add(string.Format(CultureInfo.InvariantCulture, "{0} = \"{1}\";\r\n", s2, sb2.ToString()));
                        code.Add(string.Format(CultureInfo.InvariantCulture, "$this->{0}->ExecuteWithOutputs($sql,{1},$ps,$msql);\r\n", this.Site.Name, s2));
                        for (int i = 0; i < outputParams.Count; i++)
                        {
                            code.Add(string.Format(CultureInfo.InvariantCulture, "$this->{0}->{1}=$this->{0}->outputValues['{1}'];\r\n", this.Site.Name, outputParams[i]));
                        }
                    }
                    else
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture, "$this->{0}->ExecuteNonQuery($sql,$ps,$msql);\r\n", this.Site.Name));
                    }
                    if (!string.IsNullOrEmpty(returnReceiver))
                    {
                        code.Add(string.Format(CultureInfo.InvariantCulture,
                                               "{0}=$this->{1}->errorMessage;\r\n", returnReceiver, this.Site.Name));
                    }
                    code.Add(string.Format(CultureInfo.InvariantCulture, "$this->SetServerComponentName('{0}');\r\n", this.Site.Name));
                }
            }
        }
 protected override void OnCurrentCellChanged(EventArgs e)
 {
     try
     {
         base.OnCurrentCellChanged(e);
         if (bNoEvents || !pageLoaded)
         {
             return;
         }
         bool bRowChanged = false;
         if (nCurrentCellColumn != this.CurrentCell.ColumnNumber)
         {
             OnCellNumberChanged();
             nCurrentCellColumn = this.CurrentCell.ColumnNumber;
         }
         if (nCurrentRowIndex != this.CurrentRowIndex)
         {
             nCurrentRowIndex = this.CurrentRowIndex;
             bRowChanged      = true;
         }
         if (_query != null)
         {
             if (_query.Fields.Count > 0)
             {
                 for (int i = 0; i < _query.Fields.Count; i++)
                 {
                     if (cbx != null)
                     {
                         if (cbx[i] != null)
                         {
                             cbx[i].Visible = false;
                         }
                     }
                     if (bts != null)
                     {
                         if (bts[i] != null)
                         {
                             bts[i].Visible = false;
                         }
                     }
                 }
             }
         }
         if (currentCellInSynch())
         {
             sCurCaption = _query.Tables[0].Columns[nCurrentCellColumn].Caption;
             //					if( !bReadOnly && columnEditable(nCurrentCellColumn) )
             //					{
             if (cbx != null)
             {
                 if (cbx[nCurrentCellColumn] != null)
                 {
                     if (/*!fields[nCurrentCellColumn].ReadOnly &&*/ _query.Fields[nCurrentCellColumn].OleDbType != System.Data.OleDb.OleDbType.DBTimeStamp)
                     {
                         object v0 = this[nCurrentRowIndex, nCurrentCellColumn];
                         //									string sValue = clsProperty.ToString(v0);
                         System.Drawing.Rectangle rc = this.GetCurrentCellBounds();
                         cbx[nCurrentCellColumn].SetBounds(rc.Left, rc.Top, rc.Width, rc.Height);
                         ComboLook cbxLK = cbx[nCurrentCellColumn] as ComboLook;
                         if (cbxLK != null)
                         {
                             DataRowView rv;
                             for (int i = 0; i < cbxLK.Items.Count; i++)
                             {
                                 //											string sv;
                                 object v;
                                 rv = cbxLK.Items[i] as DataRowView;
                                 if (rv != null)
                                 {
                                     v = rv[0];
                                 }
                                 else
                                 {
                                     v = cbxLK.Items[i];
                                 }
                                 if (LogicExp.Compare(v, enumLogicType2.Equal, v0))
                                 {
                                     cbxLK.bNoEvent      = true;
                                     cbxLK.SelectedIndex = i;
                                     cbxLK.bNoEvent      = false;
                                     break;
                                 }
                             }
                             if (cbxLK.SelectedIndex < 0)
                             {
                                 cbxLK.SetSelectedIndex(v0);
                             }
                             //
                         }
                         else
                         {
                             cbx[nCurrentCellColumn].SelectedIndex = -1;
                             if (this[nCurrentRowIndex, nCurrentCellColumn] != null)
                             {
                                 cbx[nCurrentCellColumn].Text = ValueConvertor.ToString(v0);
                             }
                             else
                             {
                                 cbx[nCurrentCellColumn].Text = "";
                             }
                         }
                         cbx[nCurrentCellColumn].Visible = true;
                         cbx[nCurrentCellColumn].BringToFront();
                     }
                 }
             }
             if (!ReadOnly && columnEditable(nCurrentCellColumn))
             {
                 if (bts != null)
                 {
                     if (bts[nCurrentCellColumn] != null)
                     {
                         if (/*!fields[nCurrentCellColumn].ReadOnly &&*/ _query.Fields[nCurrentCellColumn].OleDbType != System.Data.OleDb.OleDbType.DBTimeStamp)
                         {
                             System.Drawing.Rectangle rc = this.GetCurrentCellBounds();
                             bts[nCurrentCellColumn].SetBounds(rc.Left + rc.Width - 20, rc.Top, 20, rc.Height);
                             bts[nCurrentCellColumn].Visible = true;
                             bts[nCurrentCellColumn].BringToFront();
                             if (_query.Fields[nCurrentCellColumn].editor != null)
                             {
                                 if (this[nCurrentRowIndex, nCurrentCellColumn] == null)
                                 {
                                     _query.Fields[nCurrentCellColumn].editor.currentValue = "";
                                 }
                                 else
                                 {
                                     _query.Fields[nCurrentCellColumn].editor.currentValue = this[nCurrentRowIndex, nCurrentCellColumn].ToString();
                                 }
                             }
                         }
                     }
                 }
             }
             if (bRowChanged)
             {
                 System.Data.DataRow dw = CurrentRow;
                 if (dw != null)
                 {
                     for (int i = 0; i < _query.Fields.Count; i++)
                     {
                         _query.Fields[i].Value = dw[i];
                     }
                 }
                 onRowIndexChanged();
                 if (CurrentRowIndexChange != null)
                 {
                     CurrentRowIndexChange(this, new System.EventArgs());
                 }
             }
         }
         //else
         //{
         //    if (_query != null)
         //    {
         //        if (_query.Tables.Count > 0)
         //        {
         //            if (_query.Tables[0] != null)
         //            {
         //                if (nCurrentRowIndex == 0 && _query.Tables[0].Rows.Count == 0)
         //                {
         //                }
         //            }
         //        }
         //    }
         //}
     }
     catch (Exception er)
     {
         FormLog.NotifyException(er);
     }
 }
        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);
                    }
                }
            }
        }
        public override string Execute()
        {
            string sMsg = string.Empty;

            SetError(sMsg);
            ResetAffectedRows();
            SQLNoneQuery   sql         = base.ExecutionCommand;
            ConnectionItem connect     = Connection;
            DbTransaction  transaction = Transaction;

            if (sql != null && connect != null)
            {
                DbCommand cmd = connect.ConnectionObject.CreateCommand();
                if (transaction != null)
                {
                    cmd.Transaction = transaction;
                }
                bool bClosed = !connect.ConnectionObject.Opened;
                if (bClosed)
                {
                    connect.ConnectionObject.Open();
                }
                if (connect.ConnectionObject.Opened)
                {
                    try
                    {
                        int i;
                        EnumParameterStyle pstyle = connect.ParameterStyle;
                        cmd.CommandText = sql.SQL;
                        if (sql.CommandType == enmNonQueryType.StoredProcedure)
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                        }
                        else
                        {
                            cmd.CommandType = CommandType.Text;
                        }
                        int nCount = ParameterCount;
                        for (i = 0; i < nCount; i++)
                        {
                            DbParameter pam = cmd.CreateParameter();
                            if (pstyle == EnumParameterStyle.LeadingQuestionMark)
                            {
                                if (sql.Param_Name[i].StartsWith("@", StringComparison.OrdinalIgnoreCase))
                                {
                                    pam.ParameterName = string.Format(CultureInfo.InvariantCulture, "?{0}", sql.Param_Name[i].Substring(1));
                                }
                                else if (sql.Param_Name[i].StartsWith("?", StringComparison.OrdinalIgnoreCase))
                                {
                                    pam.ParameterName = sql.Param_Name[i];
                                }
                                else
                                {
                                    pam.ParameterName = string.Format(CultureInfo.InvariantCulture, "?{0}", sql.Param_Name[i]);
                                }
                            }
                            else
                            {
                                if (sql.Param_Name[i].StartsWith("@", StringComparison.OrdinalIgnoreCase))
                                {
                                    pam.ParameterName = sql.Param_Name[i];
                                }
                                else
                                {
                                    pam.ParameterName = string.Format(CultureInfo.InvariantCulture, "@{0}", sql.Param_Name[i]);
                                }
                            }
                            pam.DbType    = ValueConvertor.OleDbTypeToDbType(sql.Param_OleDbType[i]);
                            pam.Direction = this.Param_Directions[i];
                            pam.Size      = EPField.FieldDataSize(sql.Param_OleDbType[i], this.Param_DataSize[i]);
                            pam.Value     = ValueConvertor.ConvertByOleDbType(sql.Parameters[i].Value, sql.Param_OleDbType[i]);
                            cmd.Parameters.Add(pam);
                        }
                        cmd.Prepare();
                        DbDataReader dr = cmd.ExecuteReader();

                        _dataset = new DataSet("Results");
                        int n = 1;
                        while (true)
                        {
                            DataTable tbl = new DataTable(string.Format("Table{0}", n));
                            for (i = 0; i < dr.FieldCount; i++)
                            {
                                DataColumn dc = new DataColumn(dr.GetName(i), dr.GetFieldType(i));
                                tbl.Columns.Add(dc);
                            }
                            _dataset.Tables.Add(tbl);
                            while (dr.Read())
                            {
                                object[] vs = new object[dr.FieldCount];
                                for (int k = 0; k < dr.FieldCount; k++)
                                {
                                    vs[k] = dr.GetValue(k);
                                }
                                tbl.Rows.Add(vs);
                            }
                            n++;
                            if (!dr.NextResult())
                            {
                                break;
                            }
                        }
                        dr.Close();
                        if (bClosed)
                        {
                            closeConnections();
                        }
                        for (i = 0; i < nCount; i++)
                        {
                            ParameterDirection pt = cmd.Parameters[i].Direction;
                            if (pt != ParameterDirection.Input)
                            {
                                sql.Parameters[i].Value = cmd.Parameters[i].Value;
                            }
                        }
                        FireExecuteFinish();
                    }
                    catch (Exception er)
                    {
                        if (transaction != null)
                        {
                            transaction.Rollback();
                            transaction.Dispose();
                            ResetTransaction();
                            throw;
                        }
                        else
                        {
                            sMsg = ExceptionLimnorDatabase.FormExceptionText(er);
                        }
                    }
                    finally
                    {
                        if (bClosed)
                        {
                            if (connect.ConnectionObject.State != ConnectionState.Closed)
                            {
                                connect.ConnectionObject.Close();
                            }
                        }
                    }
                }
                else
                {
                    sMsg = "Database connection not set";
                }
            }
            else
            {
                sMsg = "SQL statement not set";
            }
            if (!string.IsNullOrEmpty(sMsg))
            {
                SetError(sMsg);
            }
            return(sMsg);
        }
示例#13
0
        static public System.Drawing.Color ToColor(object v)
        {
            if (v == null)
            {
                return(System.Drawing.Color.Black);
            }
            System.Drawing.Color c = System.Drawing.Color.Black;

            System.Type tp = v.GetType();
            if (tp.Equals(typeof(Color)))
            {
                c = (System.Drawing.Color)v;
            }
            else
            {
                try
                {
                    int n = Convert.ToInt32(v);
                    c = System.Drawing.Color.FromArgb(n);
                }
                catch
                {
                    string s = ValueConvertor.ToString(v);
                    s = s.Trim();
                    if (s.StartsWith("COLOR", StringComparison.OrdinalIgnoreCase))
                    {
                        s = s.Substring(5);
                        s = s.Trim();
                        if (s.Length > 2)
                        {
                            if (s[0] == '[')
                            {
                                s = s.Substring(1, s.Length - 2);
                            }
                        }
                    }
                    if (s.StartsWith("A=", StringComparison.OrdinalIgnoreCase))
                    {
                        bool bOK = false;
                        s = s.Substring(2);
                        int pos = s.IndexOf(',');
                        if (pos > 0)
                        {
                            try
                            {
                                int A = Convert.ToInt32(s.Substring(0, pos));
                                s = s.Substring(pos + 1);
                                s = s.Trim();
                                if (s.StartsWith("R=", StringComparison.OrdinalIgnoreCase))
                                {
                                    s   = s.Substring(2);
                                    pos = s.IndexOf(',');
                                    if (pos > 0)
                                    {
                                        int R = Convert.ToInt32(s.Substring(0, pos));
                                        s = s.Substring(pos + 1);
                                        s = s.Trim();
                                        if (s.StartsWith("G=", StringComparison.OrdinalIgnoreCase))
                                        {
                                            s   = s.Substring(2);
                                            pos = s.IndexOf(',');
                                            if (pos > 0)
                                            {
                                                int G = Convert.ToInt32(s.Substring(0, pos));
                                                s = s.Substring(pos + 1);
                                                s = s.Trim();
                                                if (s.StartsWith("B=", StringComparison.OrdinalIgnoreCase))
                                                {
                                                    s = s.Substring(2);
                                                    int B = Convert.ToInt32(s);
                                                    c   = System.Drawing.Color.FromArgb(A, R, G, B);
                                                    bOK = true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            catch
                            {
                                c = System.Drawing.Color.Black;
                            }
                        }
                        if (!bOK)
                        {
                            c = System.Drawing.Color.Black;
                        }
                    }
                    else
                    {
                        try
                        {
                            c = System.Drawing.Color.FromKnownColor((System.Drawing.KnownColor)Enum.Parse(typeof(System.Drawing.KnownColor), s, true));
                        }
                        catch
                        {
                            c = System.Drawing.Color.Black;
                        }
                    }
                }
            }
            return(c);
        }
        public static bool Compare(object v1, enumLogicType2 logic, object v2)
        {
            if (v1 == null || v1 == DBNull.Value)
            {
                switch (logic)
                {
                case enumLogicType2.Equal:
                    return(v2 == null);

                case enumLogicType2.LargerEqual:
                    return(v2 == null);

                case enumLogicType2.NotEqual:
                    return(v2 != null);

                case enumLogicType2.SmallerEqual:
                    return(v2 == null);

                default:
                    return(false);
                }
            }
            //v1 != null
            if (v2 == null || v2 == DBNull.Value)
            {
                switch (logic)
                {
                case enumLogicType2.NotEqual:
                    return(true);

                case enumLogicType2.Larger:
                    return(true);

                case enumLogicType2.LargerEqual:
                    return(true);

                default:
                    return(false);
                }
            }
            if ((int)logic < (int)enumLogicType2.Equal_NoCase)
            {
                System.Type     tp1 = v1.GetType();
                System.TypeCode c1  = System.Type.GetTypeCode(tp1);
                System.Type     tp2 = v2.GetType();
                System.TypeCode c2  = System.Type.GetTypeCode(tp2);
                if (IsInteger(c1))
                {
                    if (IsInteger(c2))
                    {
                        System.Int64 i1 = Convert.ToInt64(v1);
                        System.Int64 i2 = Convert.ToInt64(v2);
                        switch (logic)
                        {
                        case enumLogicType2.Equal:
                            return(i1 == i2);

                        case enumLogicType2.Larger:
                            return(i1 > i2);

                        case enumLogicType2.LargerEqual:
                            return(i1 >= i2);

                        case enumLogicType2.NotEqual:
                            return(i1 != i2);

                        case enumLogicType2.Smaller:
                            return(i1 < i2);

                        case enumLogicType2.SmallerEqual:
                            return(i1 <= i2);

                        default:
                            return(false);
                        }
                    }
                    else if (IsUInteger(c2))
                    {
                        System.UInt64 u1 = Convert.ToUInt64(v1);
                        System.UInt64 u2 = Convert.ToUInt64(v2);
                        switch (logic)
                        {
                        case enumLogicType2.Equal:
                            return(u1 == u2);

                        case enumLogicType2.Larger:
                            return(u1 > u2);

                        case enumLogicType2.LargerEqual:
                            return(u1 >= u2);

                        case enumLogicType2.NotEqual:
                            return(u1 != u2);

                        case enumLogicType2.Smaller:
                            return(u1 < u2);

                        case enumLogicType2.SmallerEqual:
                            return(u1 <= u2);

                        default:
                            return(false);
                        }
                    }
                    else
                    {
                        System.Int64 i1 = Convert.ToInt64(v1);
                        try
                        {
                            System.Int64 i2 = Convert.ToInt64(v2);
                            switch (logic)
                            {
                            case enumLogicType2.Equal:
                                return(i1 == i2);

                            case enumLogicType2.Larger:
                                return(i1 > i2);

                            case enumLogicType2.LargerEqual:
                                return(i1 >= i2);

                            case enumLogicType2.NotEqual:
                                return(i1 != i2);

                            case enumLogicType2.Smaller:
                                return(i1 < i2);

                            case enumLogicType2.SmallerEqual:
                                return(i1 <= i2);

                            default:
                                return(false);
                            }
                        }
                        catch
                        {
                        }
                        return(false);
                    }
                }
                else if (IsUInteger(c1))
                {
                    if (IsInteger(c2))
                    {
                        System.UInt64 u1 = Convert.ToUInt64(v1);
                        System.UInt64 u2 = Convert.ToUInt64(v2);
                        switch (logic)
                        {
                        case enumLogicType2.Equal:
                            return(u1 == u2);

                        case enumLogicType2.Larger:
                            return(u1 > u2);

                        case enumLogicType2.LargerEqual:
                            return(u1 >= u2);

                        case enumLogicType2.NotEqual:
                            return(u1 != u2);

                        case enumLogicType2.Smaller:
                            return(u1 < u2);

                        case enumLogicType2.SmallerEqual:
                            return(u1 <= u2);

                        default:
                            return(false);
                        }
                    }
                    else if (IsUInteger(c2))
                    {
                        System.UInt64 u1 = Convert.ToUInt64(v1);
                        System.UInt64 u2 = Convert.ToUInt64(v2);
                        switch (logic)
                        {
                        case enumLogicType2.Equal:
                            return(u1 == u2);

                        case enumLogicType2.Larger:
                            return(u1 > u2);

                        case enumLogicType2.LargerEqual:
                            return(u1 >= u2);

                        case enumLogicType2.NotEqual:
                            return(u1 != u2);

                        case enumLogicType2.Smaller:
                            return(u1 < u2);

                        case enumLogicType2.SmallerEqual:
                            return(u1 <= u2);

                        default:
                            return(false);
                        }
                    }
                    else
                    {
                        System.UInt64 u1 = Convert.ToUInt64(v1);
                        try
                        {
                            System.UInt64 u2 = Convert.ToUInt64(v2);
                            switch (logic)
                            {
                            case enumLogicType2.Equal:
                                return(u1 == u2);

                            case enumLogicType2.Larger:
                                return(u1 > u2);

                            case enumLogicType2.LargerEqual:
                                return(u1 >= u2);

                            case enumLogicType2.NotEqual:
                                return(u1 != u2);

                            case enumLogicType2.Smaller:
                                return(u1 < u2);

                            case enumLogicType2.SmallerEqual:
                                return(u1 <= u2);

                            default:
                                return(false);
                            }
                        }
                        catch
                        {
                        }
                        return(false);
                    }
                }
                else if (c1 == System.TypeCode.Boolean || c2 == System.TypeCode.Boolean)
                {
                    bool b1 = ValueConvertor.ToBool(v1);
                    bool b2 = ValueConvertor.ToBool(v2);
                    switch (logic)
                    {
                    case enumLogicType2.Equal:
                        return(b1 == b2);

                    case enumLogicType2.NotEqual:
                        return(b1 != b2);

                    default:
                        return(false);
                    }
                }
                else if (c1 == System.TypeCode.DateTime || c2 == System.TypeCode.DateTime)
                {
                    System.DateTime d1 = ValueConvertor.ToDateTime(v1);
                    System.DateTime d2 = ValueConvertor.ToDateTime(v2);
                    switch (logic)
                    {
                    case enumLogicType2.Equal:
                        return(d1 == d2);

                    case enumLogicType2.Larger:
                        return(d1 > d2);

                    case enumLogicType2.LargerEqual:
                        return(d1 >= d2);

                    case enumLogicType2.NotEqual:
                        return(d1 != d2);

                    case enumLogicType2.Smaller:
                        return(d1 < d2);

                    case enumLogicType2.SmallerEqual:
                        return(d1 <= d2);

                    default:
                        return(false);
                    }
                }
                else if (IsDecimal(c1) || IsDecimal(c2))
                {
                    double d1 = ValueConvertor.ToDouble(v1);
                    double d2 = ValueConvertor.ToDouble(v2);
                    switch (logic)
                    {
                    case enumLogicType2.Equal:
                        return(d1 == d2);

                    case enumLogicType2.Larger:
                        return(d1 > d2);

                    case enumLogicType2.LargerEqual:
                        return(d1 >= d2);

                    case enumLogicType2.NotEqual:
                        return(d1 != d2);

                    case enumLogicType2.Smaller:
                        return(d1 < d2);

                    case enumLogicType2.SmallerEqual:
                        return(d1 <= d2);

                    default:
                        return(false);
                    }
                }
                else if (tp1.Equals(typeof(System.Drawing.Color)) || tp2.Equals(typeof(System.Drawing.Color)))
                {
                    int d1 = ValueConvertor.ToColor(v1).ToArgb();
                    int d2 = ValueConvertor.ToColor(v2).ToArgb();
                    switch (logic)
                    {
                    case enumLogicType2.Equal:
                        return(d1 == d2);

                    case enumLogicType2.Larger:
                        return(d1 > d2);

                    case enumLogicType2.LargerEqual:
                        return(d1 >= d2);

                    case enumLogicType2.NotEqual:
                        return(d1 != d2);

                    case enumLogicType2.Smaller:
                        return(d1 < d2);

                    case enumLogicType2.SmallerEqual:
                        return(d1 <= d2);

                    default:
                        return(false);
                    }
                }
            }
            //string comparing
            string s1 = v1.ToString();
            string s2 = v2.ToString();
            bool   bCompareAsNumbers = false;
            double dv1 = 0;
            double dv2 = 0;

            if (logic == enumLogicType2.Equal ||
                logic == enumLogicType2.Larger ||
                logic == enumLogicType2.LargerEqual ||
                logic == enumLogicType2.NotEqual ||
                logic == enumLogicType2.Smaller ||
                logic == enumLogicType2.SmallerEqual)
            {
                if (double.TryParse(s1, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out dv1))
                {
                    if (double.TryParse(s2, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out dv2))
                    {
                        bCompareAsNumbers = true;
                    }
                }
            }
            if (bCompareAsNumbers)
            {
                switch (logic)
                {
                case enumLogicType2.Equal:
                    return(dv1 == dv2);

                case enumLogicType2.Larger:
                    return(dv1 > dv2);

                case enumLogicType2.LargerEqual:
                    return(dv1 >= dv2);

                case enumLogicType2.NotEqual:
                    return(dv1 != dv2);

                case enumLogicType2.Smaller:
                    return(dv1 < dv2);

                case enumLogicType2.SmallerEqual:
                    return(dv1 <= dv2);

                default:
                    bCompareAsNumbers = false;
                    break;
                }
            }
            {
                switch (logic)
                {
                case enumLogicType2.BeginWith:
                    return(s1.StartsWith(s2, StringComparison.Ordinal));

                case enumLogicType2.BeginWith_NoCase:
                    return(s1.StartsWith(s2, StringComparison.OrdinalIgnoreCase));

                case enumLogicType2.Contains:
                    return(s1.IndexOf(s2, StringComparison.Ordinal) >= 0);

                case enumLogicType2.Contains_NoCase:
                    return(s1.IndexOf(s2, StringComparison.OrdinalIgnoreCase) >= 0);

                case enumLogicType2.EndWith:
                    return(s1.EndsWith(s2, StringComparison.Ordinal));

                case enumLogicType2.EndWith_NoCase:
                    return(s1.EndsWith(s2, StringComparison.OrdinalIgnoreCase));

                case enumLogicType2.Included:
                    return(s2.IndexOf(s1, StringComparison.Ordinal) >= 0);

                case enumLogicType2.Included_NoCase:
                    return(s2.IndexOf(s1, StringComparison.OrdinalIgnoreCase) >= 0);

                case enumLogicType2.Equal:
                    return(string.Compare(s1, s2, StringComparison.Ordinal) == 0);

                case enumLogicType2.Equal_NoCase:
                    return(string.Compare(s1, s2, StringComparison.OrdinalIgnoreCase) == 0);

                case enumLogicType2.Larger:
                    return(s1.CompareTo(s2) > 0);

                case enumLogicType2.LargerEqual:
                    return(s1.CompareTo(s2) >= 0);

                case enumLogicType2.NotEqual:
                    return(string.Compare(s1, s2, StringComparison.Ordinal) != 0);

                case enumLogicType2.NotEqual_NoCase:
                    return(string.Compare(s1, s2, StringComparison.OrdinalIgnoreCase) != 0);

                case enumLogicType2.Smaller:
                    return(s1.CompareTo(s2) < 0);

                case enumLogicType2.SmallerEqual:
                    return(s1.CompareTo(s2) <= 0);

                case enumLogicType2.BeginOf:
                    return(s2.StartsWith(s1, StringComparison.Ordinal));

                case enumLogicType2.BeginOf_NoCase:
                    return(s2.StartsWith(s1, StringComparison.OrdinalIgnoreCase));

                case enumLogicType2.EndOf:
                    return(s2.EndsWith(s1, StringComparison.Ordinal));

                case enumLogicType2.EndOf_NoCase:
                    return(s2.EndsWith(s1, StringComparison.OrdinalIgnoreCase));

                default:
                    return(false);
                }
            }
        }