Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmdStr"></param>
        /// <returns></returns>
        internal static ICmd ParseSqlCmdString(string cmdStr, CoreEA.ICoreEAHander dbe)
        {
            ICmd curCmd = null;

            if (string.IsNullOrEmpty(cmdStr))
            {
                ProcessException.DisplayErrors(new Exception("Empty Command"));
                return(null);
            }
            try
            {
                cmdStr = cmdStr.TrimStart();
                cmdStr = cmdStr.TrimEnd();

                //Can't to lower , otherwise the insert data will never 大写
                //cmdText = cmdText.ToLower();
                string tempCmdText = cmdStr.ToLower();
                if (tempCmdText.StartsWith("select"))
                {
                    curCmd = new SelectCmd(dbe);
                }
                else if (tempCmdText.StartsWith("insert"))
                {
                    curCmd = new InsertCmd(dbe);
                }
                else if (tempCmdText.StartsWith("update"))
                {
                    curCmd = new UpdateCmd(dbe);
                }
                else if (tempCmdText.StartsWith("delete"))
                {
                    curCmd = new DeleteCmd(dbe);
                }
                else if (tempCmdText.StartsWith("alter") || (tempCmdText.StartsWith("drop")))
                {
                    curCmd = new SpecialCmd(dbe);
                }
                else if (tempCmdText.StartsWith("create"))
                {
                    curCmd = new CreateCmd(dbe);
                }
                else if (tempCmdText.StartsWith("sp_rename"))
                {
                    curCmd = new SpecialCmd(dbe);
                }
                else
                {
                    curCmd = null;
                    //throw new Exception("ErrorMsg_CannotParseSqlCmd".GetFromResourece());
                }
            }
            catch (Exception ee)
            {
                ProcessException.DisplayErrors(ee);
            }

            return(curCmd);
        }
Beispiel #2
0
        void dataGridControl1_CellEndEdit(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            object celValue = dataGridViewForCreateTable.CurrentCell.Value;

            if (celValue == null)
            {
                return;
            }
            try
            {
                if ((e.ColumnIndex == 1) && (dataGridViewForCreateTable.CurrentRow.Cells[2].Value == null))
                {
                    string ttt = celValue.ToString();
                    if (ttt == "nvarchar")
                    {
                        dataGridViewForCreateTable.CurrentRow.Cells[1].Value = "nvarchar";
                        dataGridViewForCreateTable.CurrentRow.Cells[2].Value = "100";
                    }
                    if (ttt == "int")
                    {
                        dataGridViewForCreateTable.CurrentRow.Cells[1].Value = "int";
                        dataGridViewForCreateTable.CurrentRow.Cells[2].Value = "8";
                    }
                    if (ttt == "integer")
                    {
                        dataGridViewForCreateTable.CurrentRow.Cells[1].Value = "integer";
                        dataGridViewForCreateTable.CurrentRow.Cells[2].Value = "8";
                    }
                    if (ttt == "smallint")
                    {
                        dataGridViewForCreateTable.CurrentRow.Cells[1].Value = "smallint";
                        dataGridViewForCreateTable.CurrentRow.Cells[2].Value = "4";
                    }

                    if (dataGridViewForCreateTable.CurrentRow.Cells[ColumnName_Unique].Value == null)
                    {
                        dataGridViewForCreateTable.CurrentRow.Cells[ColumnName_Unique].Value = "No";
                    }
                    if (dataGridViewForCreateTable.CurrentRow.Cells[ColumnName_PrimaryKey] == null)
                    {
                        dataGridViewForCreateTable.CurrentRow.Cells[ColumnName_PrimaryKey].Value = "No";
                    }
                    if (dataGridViewForCreateTable.CurrentRow.Cells[ColumnName_AllowNull].Value == null)
                    {
                        dataGridViewForCreateTable.CurrentRow.Cells[ColumnName_AllowNull].Value = "No";
                    }
                }
            }
            catch (Exception ee)
            {
                ProcessException.DisplayErrors(ee);
            }
        }
Beispiel #3
0
        private void butOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Properties.Settings.Default["AutoBackupOldVersionFileBeforeUpgrade"] = (bool)checkBox1.IsChecked;
                Properties.Settings.Default.Save();


                Properties.Settings.Default.UseSpeakInsteadOfMsgBox = (bool)chkIsUseSpeakInsteadOfMsg.IsChecked;
                Properties.Settings.Default.CmdTextFontSize         = (int)txtFontSize.Value;
                Properties.Settings.Default.Save();
                Close();
            }
            catch (Exception ee)
            {
                ProcessException.DisplayErrors(ee);
            }
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            int recordCount = 10000;

            using (PopupForm p = new PopupForm())
            {
                p.X_NotifyStr = "Record Count";
                if (p.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    int outValue;
                    if (!int.TryParse(p.X_Result, out outValue))
                    {
                        return;
                    }
                    recordCount = outValue;
                }
                else
                {
                    return;
                }
            }

            string testDb    = DateTime.Now.Second.ToString() + "test.sdf";
            string testTable = "testTable";

            if (!App.MainEngineer.CreateDatabase(new LoginInfo_SSCE()
            {
                DbName = testDb
            }))
            {
                return;
            }
            App.MainEngineer.Open(new CoreEA.LoginInfo.LoginInfo_SSCE()
            {
                DbName = testDb, Pwd = "", IsEncrypted = false
            });

            if (!App.MainEngineer.IsOpened)
            {
                throw new Exception("Can't Open");
            }

            //List<CreateTableArgs> argsList=new List<CreateTableArgs>();

            //CreateTableArgs args=new CreateTableArgs();
            //args.allowNulls = false;
            //args.dataLength = 0;
            //args.dataType="int";
            //args.fieldName="id";
            //args.isUnique = false;
            //args.isPrimaryKey = false;
            //argsList.Add(args);

            BaseTableSchema tableSchame = new BaseTableSchema();

            tableSchame.Columns.Add(new BaseColumnSchema()
            {
                ColumnName = "id", ColumnType = "int"
            });

            try
            {
                App.MainEngineer.CreateTable(tableSchame);

                string          sqlCmd = string.Empty;
                SqlCeConnection conn   = new SqlCeConnection(string.Format("Data source={0}", testDb));
                SqlCeCommand    cmd    = new SqlCeCommand();
                cmd.Connection = conn;
                conn.Open();

                Stopwatch watch = new Stopwatch();
                watch.Start();
                for (int i = 0; i < recordCount; i++)
                {
                    sqlCmd          = string.Format("insert into {0} values ({1})", testTable, i);
                    cmd.CommandText = sqlCmd;
                    cmd.ExecuteNonQuery();
                }

                watch.Stop();
                long sqlDirectTime = watch.ElapsedMilliseconds;

                watch.Reset();
                watch.Start();

                cmd.CommandText = string.Format("INSERT INTO {0} VALUES (?)", testTable);
                cmd.Parameters.Add("@id", SqlDbType.Int);
                cmd.Prepare();
                for (int i = 0; i < recordCount; i++)
                {
                    cmd.Parameters[0].Value = i;
                    cmd.ExecuteNonQuery();
                }

                watch.Stop();
                long sqlParaTime = watch.ElapsedMilliseconds;
                watch.Reset();

                watch.Start();

                cmd.CommandText = testTable;
                cmd.CommandType = CommandType.TableDirect;
                SqlCeResultSet       st  = cmd.ExecuteResultSet(ResultSetOptions.Updatable);
                SqlCeUpdatableRecord rec = st.CreateRecord();
                for (int i = 0; i < recordCount; i++)
                {
                    rec.SetInt32(0, i);

                    st.Insert(rec);
                }
                watch.Stop();
                long sqlceResultSetTime = watch.ElapsedMilliseconds;

                //watch.Start();

                //cmd.CommandText = testTable;
                //cmd.CommandType = CommandType.TableDirect;
                //SqlCeResultSet st = cmd.ExecuteResultSet(ResultSetOptions.Updatable);
                //SqlCeUpdatableRecord rec =
                //for (int i = 0; i < recordCount; i++)
                //{
                //    rec.SetInt32(0, i);

                //    st.Insert(rec);
                //}
                //watch.Stop();
                long sqlceUpdateResultSetTime = 100;// watch.ElapsedMilliseconds;



                cmd.Dispose();
                conn.Close();

                MessageBox.Show(string.Format("Test Result is \r\nDirect sql command used {0} \r\nUse parameters used{1}\r\nUse SqlceResultSet used{2}\r\nUpdate Sqlce ResultSet{3}\r\n", sqlDirectTime, sqlParaTime, sqlceResultSetTime, sqlceUpdateResultSetTime));
            }
            catch (Exception ee)
            {
                ProcessException.DisplayErrors(ee);
            }
        }
Beispiel #5
0
        private void DoOKWhenCreateTable()
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                "CreatTableSchema_NeedTableName".GetFromResourece().Notify();
                return;
            }
            string tableName = textBox1.Text;

            if (dataGridViewForCreateTable.Rows.Count > 0)
            {
                List <CreateTableArgs> createTableArgsList = new List <CreateTableArgs>();

                foreach (System.Windows.Forms.DataGridViewRow row in this.dataGridViewForCreateTable.Rows)
                {
                    CreateTableArgs args = new CreateTableArgs();
                    if (row.Cells[ColumnName_AllowNull].Value != null)
                    {
                        try
                        {
                            args.allowNulls   = CommonUtil.SwitchToBool(row.Cells[ColumnName_AllowNull].Value);
                            args.isPrimaryKey = CommonUtil.SwitchToBool(row.Cells[ColumnName_PrimaryKey].Value);
                            args.isUnique     = CommonUtil.SwitchToBool(row.Cells[ColumnName_Unique].Value);
                            if (row.Cells[ColumnName_DataType].Value == null)
                            {
                                "Data Type Can not be empty".Notify();
                                return;
                            }
                            args.dataType = row.Cells[ColumnName_DataType].Value.ToString();
                            if (row.Cells[ColumnName_Length].Value == null)
                            {
                                "Column Length Can not be empty".Notify();
                                return;
                            }
                            args.dataLength = int.Parse(row.Cells[ColumnName_Length].Value.ToString());

                            if (row.Cells[ColumnName_ColumName].Value == null)
                            {
                                "Column Name Can not be empty".Notify();
                                return;
                            }
                            args.fieldName = row.Cells[ColumnName_ColumName].Value.ToString();

                            //Some type no need length properties ,so set empty
                            //These types include int,interge,
                            if (GlobalDefine.NoLenghtType.Collections.Contains(args.dataType))
                            {
                                args.dataLength = 0;
                            }
                            createTableArgsList.Add(args);
                        }
                        catch (Exception ee)
                        {
                            ProcessException.DisplayErrors(ee);
                        }
                    }
                }

                if (App.MainEngineer.CreateTableWithSchemaInfo(createTableArgsList, tableName))
                {
                    if (RaiseAddNewTable != null)
                    {
                        RaiseAddNewTable();
                    }

                    "CreateTableSchmea_CreateTableOkMsg".GetFromResourece().Notify();

                    Close();
                }
            }
        }
Beispiel #6
0
        private void processGenerate(string item)
        {
            try
            {
                CodeCompileUnit targetUnit = new CodeCompileUnit();

                CodeNamespace ns = new CodeNamespace(Properties.Settings.Default.MM_NamespaceName);

                ns.Imports.Add(new CodeNamespaceImport("System"));
                ns.Imports.Add(new CodeNamespaceImport("System.Text"));

                targetUnit.Namespaces.Add(ns);

                CodeTypeDeclaration ct = new CodeTypeDeclaration("Table_" + item);
                ct.IsClass    = true;
                ct.Attributes = MemberAttributes.Public | MemberAttributes.Static | MemberAttributes.Final;
                //ct.IsPartial = true;

                ns.Types.Add(ct);

                List <string> ColumnLists = App.MainEngineer.GetColumnNameListFromTable(item);

                if (ColumnLists.Count < 1)
                {
                    return;
                }

                foreach (string columnName in ColumnLists)
                {
                    CodeMemberField member = new CodeMemberField();
                    member.Name           = "_" + columnName;
                    member.Type           = new CodeTypeReference(typeof(string));
                    member.Attributes     = MemberAttributes.Private | MemberAttributes.Static;
                    member.InitExpression = new CodePrimitiveExpression(columnName);
                    ct.Members.Add(member);

                    CodeMemberProperty p = new CodeMemberProperty();
                    p.Name       = columnName;
                    p.Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.Static;
                    p.HasGet     = true;
                    p.HasSet     = false;

                    p.Type = new CodeTypeReference(typeof(string));
                    //p.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_"+columnName)));
                    p.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("_" + columnName)));

                    ct.Members.Add(p);
                }

                CodeDomProvider      provider = CodeDomProvider.CreateProvider("CSharp");
                CodeGeneratorOptions options  = new CodeGeneratorOptions();
                options.BracingStyle = "C";
                using (StreamWriter sm = new StreamWriter(String.Format("{0}\\{1}.cs", this.textBox1.Text, item)))
                {
                    provider.GenerateCodeFromCompileUnit(targetUnit, sm, options);
                }
            }
            catch (Exception ee)
            {
                errorTableList.Add(item);
                ProcessException.DisplayErrors(ee);
            }
        }