private void Guardar(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(this.Model.Configuration.Empresa))
                {
                    CustomMessageBox.Show("Debe indicar un nombre para esta cadena.", "La conexión no es valida", CustomMessageBoxButton.OK, CustomMessageBoxImage.Warning);
                    return;
                }

                var SqlServer = new SQLServerConnection(this.Model.ConnectionString);
                SqlServer.ConnectionString = new SqlConnectionStringBuilder(this.Model.ConnectionString);
                if (SqlServer.TestConnection(this.Model.ConnectionString) is Exception ex)
                {
                    if (CustomMessageBox.ShowYesNo(
                            "La conexión actual no es valida\n" + ex.Message + "\n¿Desea guardarla de todas formas?",
                            "La conexión no es valida", "Si", "No", CustomMessageBoxImage.Question) == CustomMessageBoxResult.No)
                    {
                        return;
                    }
                }
                SqlServer.ConnectionString = new SqlConnectionStringBuilder(this.Model.ConnectionString);
                this.Model.SqlServer       = SqlServer;
                this.Model.Save();
                this.Close();
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex, "Al  guardar la cadena de conexión");
            }
        }
Ejemplo n.º 2
0
        //关系数据库
        private void bGalleryRelationalDatabase_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.panelControl_Navigation.Controls.Clear();
            this.panelControl_Navigation.Controls.Add(ucNaviRDB);

            DataTable dt = SQLServerConnection.GetDatabaseSchema();

            if (dt == null)
            {
                return;
            }
            if (dt.Rows.Count == 0)
            {
                return;
            }
            this.ucNaviRDB.TreeList.KeyFieldName    = "id";                                //主要显示内容
            this.ucNaviRDB.TreeList.ParentFieldName = "TABLE_CATALOG";                     //目录
            this.ucNaviRDB.TreeList.DataSource      = dt;                                  //数据库
            DevExpress.XtraTreeList.Columns.TreeListColumnCollection col = this.ucNaviRDB.TreeList.Columns;
            this.ucNaviRDB.TreeList.Columns["TABLE_NAME"].SortOrder = SortOrder.Ascending; //排序
            //显示内容
            for (int i = 0; i < ucNaviRDB.TreeList.Columns.Count; i++)
            {
                if (ucNaviRDB.TreeList.Columns[i].FieldName != "TABLE_NAME")
                {
                    ucNaviRDB.TreeList.Columns[i].Visible = false;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Update specific resource
        /// </summary>
        /// <returns></returns>
        public int update(Entidad.User.User user)
        {
            int retorno = 0;

            try
            {
                #region login example using SP
                SqlCommand cmd = new SqlCommand("sp_user_insert", SQLServerConnection.open());
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@name", user.Id_);
                cmd.Parameters.AddWithValue("@name", user.Name_);
                cmd.Parameters.AddWithValue("@last_name", user.LastName_);
                cmd.Parameters.AddWithValue("@email", user.Email_);
                cmd.Parameters.AddWithValue("@password", user.Password_);
                retorno = cmd.ExecuteNonQuery();
                #endregion

                return(retorno);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                SQLServerConnection.close();
            }
        }
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            AnnouncementData.calculateErrors();

            if (organiserCombobox.SelectedIndex <= -1)
            {
                MessageBox.Show("Please select the department which is passing this information.");
            }
            else if (AnnouncementData.noDepartmentSelected)
            {
                MessageBox.Show("Please select at least one department which this announcement/notification has to be shown to.");
            }
            else
            {
                SqlCommand cmd = SQLServerConnection.initializeSqlCommand("insert into Announcement (event_heading, event_desc, org_branch, elig_branch, date_created) values (@heading, @desc, @org, @elig, @date)");
                cmd.Parameters.AddWithValue("@heading", AnnouncementData.announcementTitle);
                cmd.Parameters.AddWithValue("@desc", AnnouncementData.announcementDetails);
                cmd.Parameters.AddWithValue("@org", organiserCombobox.SelectedIndex);
                cmd.Parameters.AddWithValue("@elig", AnnouncementData.eligibleBranches());

                DateTime myDateTime       = DateTime.Now;
                string   sqlFormattedDate = myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff");

                cmd.Parameters.AddWithValue("@date", sqlFormattedDate);

                cmd.ExecuteNonQuery();

                cmd.Parameters.Clear();
                SQLServerConnection.closeConnection();

                AnnouncementWindow aw = new AnnouncementWindow(true);
                aw.Show();
                this.Close();
            }
        }
Ejemplo n.º 5
0
        public static List <ItemList> GetItemList(SqlConnection SQLconn)
        {
            List <ItemList> IL = new List <ItemList>();

            using (SqlCommand command = new SqlCommand("dbo.GetFoodList", SQLconn))
            {
                command.CommandType = CommandType.StoredProcedure;
                SQLconn.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ItemList tempSL = new ItemList();
                        tempSL.FoodID          = reader.GetInt32(0);
                        tempSL.StallID         = reader.GetInt32(1);
                        tempSL.FoodTypeID      = reader.GetInt32(2);
                        tempSL.FoodName        = reader.GetString(3);
                        tempSL.FoodDescription = reader.GetString(4);
                        tempSL.FoodPrice       = reader.GetDecimal(5);
                        IL.Add(tempSL);
                    }
                }
                SQLServerConnection.CloseSQLConnection(SQLconn);
            }
            return(IL);
        }
Ejemplo n.º 6
0
        private void loadUserData()
        {
            string mySQL = string.Empty;

            mySQL += "SELECT id,Department,HostName,Protecter FROM logindata";
            mySQL += "  where HostName = '" + hostname + "'";
            DataTable userdata = SQLServerConnection.executeSQL(mySQL);

            dataGridView1.DataSource            = userdata;
            dataGridView1.Columns[0].HeaderText = "Id";
            dataGridView1.Columns[1].HeaderText = "Department";
            dataGridView1.Columns[2].HeaderText = "HostName";
            dataGridView1.Columns[3].HeaderText = "Protecter";
            dataGridView1.Columns[0].Width      = 100;
            dataGridView1.Columns[1].Width      = 100;
            dataGridView1.Columns[2].Width      = 100;
            dataGridView1.Columns[3].Width      = 100;
            if (userdata.Rows.Count > 0)
            {
                MessageBox.Show("本機電腦已註冊過");
            }
            else
            {
                MessageBox.Show("本機電腦尚未註冊");
            }
        }
Ejemplo n.º 7
0
        public bool EnsureDeviceIsRegistred(SQLServerConnection SQLH)
        {
            SyncDevicesInfo deviceInfo;

            //SQL SERVER
            if (!IsDeviceRegistered(SQLH))
            {
                deviceInfo = new SyncDevicesInfo()
                {
                    DeviceId     = DeviceId,
                    LastTimeSeen = DateTime.Now,
                    Name         = IDeviceInfo.DeviceName
                };
                SQLH.Insert(deviceInfo);
            }
            else
            {
                deviceInfo = SQLH.Table <SyncDevicesInfo>().FirstOrDefault(x => x.DeviceId == DeviceId);
                if (deviceInfo is null)
                {
                    return(IsDeviceRegistered(SQLH));
                }
                deviceInfo.LastTimeSeen = DateTime.Now;
                SQLH.Update(deviceInfo);
            }
            return(IsDeviceRegistered(SQLH));
        }
Ejemplo n.º 8
0
        //Announcement
        public void updateAnnouncement()
        {
            SqlCommand    cmd    = SQLServerConnection.initializeSqlCommand("select event_desc from Announcement");
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                notificationDetails.Text = (reader["event_desc"].ToString());
            }
            cmd.Parameters.Clear(); reader.Close();

            cmd    = SQLServerConnection.initializeSqlCommand("select date_created from Announcement");
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                dateLabel.Content = (reader["date_created"].ToString());
            }
            cmd.Parameters.Clear(); reader.Close();

            cmd    = SQLServerConnection.initializeSqlCommand("select event_heading from Announcement");
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                notificationLabel.Content = (reader["event_heading"].ToString());
            }
            cmd.Parameters.Clear(); reader.Close();
            SQLServerConnection.closeConnection();
        }
Ejemplo n.º 9
0
 private void ConnectionButton_Click(object sender, EventArgs e)
 {
     if (this.ConnectionDetails1.Text == "Server Name")
     {
         SQLServerConnection databaseConnection = new SQLServerConnection(this.ConnectionDetailsText1.Text,
                                                                          this.ConnectionDetailsText2.Text, this.ConnectionDetailsText3.Text, this.ConnectionDetailsText4.Text);
         String result = databaseConnection.createConnection();
         MessageBox.Show(result);
         SqlConnection dbConnection = databaseConnection.getDatabaseConnection();
         if (result == "Connection Established. Press OK to continue.")
         {
             new SQLServerView(databaseConnection).Show();
             this.Dispose();
         }
     }
     else
     {
         OracleDBConnection databaseConnection = new OracleDBConnection(this.ConnectionDetailsText1.Text,
                                                                        this.ConnectionDetailsText2.Text, this.ConnectionDetailsText4.Text);
         String result = databaseConnection.createConnection();
         MessageBox.Show(result);
         if (result == "Connection Established. Press OK to continue.")
         {
             new OracleView(databaseConnection).Show();
             this.Dispose();
         }
     }
 }
Ejemplo n.º 10
0
        private void StudentViewForm_Load(object sender, EventArgs e)
        {
            //Create SQL Source connection where your DB is locate
            //String source = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Andrew Nguyen\\Documents\\Projects\\Blackboard_Application\\BlackBoard_Application\\StudentInfo.mdf;Integrated Security=True";

            var sqlClass = new SQLServerConnection(); // This calls the class for SQL

            sqlClass.OpenConnection();                // Open SQL connection

            //SQL query statement to select all information from studentinformation table where username is equal to the passing input from Login Form input
            string mySql = "SELECT * FROM StudentInformation WHERE username ='******'";

            //SqlClass.ExecuteQueries(mySql);

            var reader = sqlClass.DataReader(mySql);

            while (reader.Read()) //This if statement will pass ALL values into the textbox as a string to each one for the right username
            {
                school_IDTextBox.Text       = (reader["School ID"].ToString());
                first_NameTextBox.Text      = (reader["first_Name"].ToString());
                last_NameTextBox.Text       = (reader["last_Name"].ToString());
                course_TakenTextBox.Text    = (reader["Course Taken"].ToString());
                class_1_MidtermTextBox.Text = (reader["Class 1 Midterm"].ToString());
                class_2_MidtermTextBox.Text = (reader["Class 2 Midterm"].ToString());
                class_3_MidtermTextBox.Text = (reader["Class 3 Midterm"].ToString());
                class_4_MidtermTextBox.Text = (reader["Class 4 Midterm"].ToString());
                class_1_FinalsTextBox.Text  = (reader["Class 1 Finals"].ToString());
                class_2_FinalsTextBox.Text  = (reader["Class 2 Finals"].ToString());
                class_3_FinalsTextBox.Text  = (reader["Class 3 Finals"].ToString());
                class_4_FinalsTextBox.Text  = (reader["Class 4 Finals"].ToString());
                //statement create GPA calculation
                gPATextBox.Text = (reader["GPA"].ToString());
            }
            sqlClass.CloseConnection(); // closes the connection
        }
Ejemplo n.º 11
0
 private void EnsureTableExists(SQLServerConnection SQLH)
 {
     if (!SQLH.TableExists <SyncDevicesInfo>())
     {
         SQLH.CreateTable <SyncDevicesInfo>();
     }
 }
        public SQLServerSessionDetails(SQLServerConnection connection)
        {
            InitializeComponent();
            this.dbConnection = connection;
            SqlConnection databaseConnection = connection.getDatabaseConnection();
            String        query = "SELECT spid, hostname, db_name(dbid) as DatabaseName, loginame, cmd, status "
                                  + "FROM master.dbo.sysprocesses "
                                  + "WHERE program_name = 'ORACLE-SQL-SERVER-CLIENT'"
                                  + "AND db_name(dbid) = '"
                                  + this.dbConnection.getDatabaseConnection().Database + "'";
            SqlCommand    command = new SqlCommand(query, databaseConnection);
            SqlDataReader reader;

            command.CommandText = query;
            command.CommandType = CommandType.Text;
            reader = command.ExecuteReader();

            while (reader.Read())
            {
                this.sessionListing.Rows.Add("SPID", reader["spid"]);
                this.sessionListing.Rows.Add("HOST", reader["hostname"]);
                this.sessionListing.Rows.Add("DATABASE", reader["DatabaseName"]);
                this.sessionListing.Rows.Add("USER", reader["loginame"]);
                this.sessionListing.Rows.Add("COMMAND", reader["cmd"]);
                this.sessionListing.Rows.Add("STATUS", reader["status"]);
            }
            reader.Close();
        }
Ejemplo n.º 13
0
        private bool IsDeviceRegistered(SQLServerConnection SQLH)
        {
            EnsureTableExists(SQLH);
            bool registered = SQLH.Table <SyncDevicesInfo>().Any(x => x.DeviceId == DeviceId);

            this.RegisterStatus = registered ? DeviceRegisterStatus.Registered : DeviceRegisterStatus.NotRegistered;
            return(registered);
        }
Ejemplo n.º 14
0
        // Count for Previous page index
        public static int getCount()
        {
            SqlCommand cmd = SQLServerConnection.initializeSqlCommand("select count(*) from Announcement ");

            AnnouncementData.count = (int)cmd.ExecuteScalar();
            cmd.Parameters.Clear();
            return(AnnouncementData.count);
        }
Ejemplo n.º 15
0
 public SQLServerDll(String tableName, SQLServerConnection connection, bool option)
 {
     InitializeComponent();
     this.tableName    = tableName;
     this.dbConnection = connection;
     this.Text         = tableName + "@" + dbConnection.getDatabaseConnection().Database;
     refreshInitialize();
 }
Ejemplo n.º 16
0
 public procedureViewerSQLServer(String procedureName, SQLServerConnection connection, bool option)
 {
     InitializeComponent();
     this.procedureName = procedureName;
     this.dbConnection  = connection;
     this.Text          = procedureName + "@" + dbConnection.getDatabaseConnection().Database;
     refreshInitialize();
 }
Ejemplo n.º 17
0
        private void loginButton_Click(object sender, RoutedEventArgs e)
        {
            loginButton.Background = (Brush)(new BrushConverter().ConvertFrom("#FF82B3C9"));
            exceptionLabel.Content = "";

            if (!(isTeacher || isStudent))
            {
                MessageBox.Show(" Please Select Student Or Teacher.", "Select User Type");
            }
            else
            {   //SQL Command template.
                //SqlCommand cmd = SQLServerConnection.initializeSqlCommand("");
                //body
                //SQLServerConnection.closeConnection();

                SqlCommand cmd = SQLServerConnection.initializeSqlCommand("select count(*) from LoginTable where usn=@usn and pwd=@pwd and usertype=@usertype");

                char usertype         = ' ';
                bool studentOrTeacher = false;

                if (isTeacher)
                {
                    usertype         = 't';
                    studentOrTeacher = true;
                }
                if (isStudent)
                {
                    usertype         = 's';
                    studentOrTeacher = false;
                }


                cmd.Parameters.AddWithValue("@usn", userIdValue.Text);
                cmd.Parameters.AddWithValue("@pwd", passwordValue.Password);
                cmd.Parameters.AddWithValue("@usertype", usertype);

                int count = Convert.ToInt32(cmd.ExecuteScalar());

                if (count > 0)
                {
                    AnnouncementWindow announcement = new AnnouncementWindow(studentOrTeacher);
                    announcement.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Username or password is incorrect.");
                    userIdValue.Text       = "";
                    passwordValue.Password = "";
                }

                cmd.Parameters.Clear();
                SQLServerConnection.closeConnection();
            }

            /*if(isTeacher&&isStudent)
             *  exceptionLabel.Content = "**Student/Teacher Button NOT Selected**";*/
        }
Ejemplo n.º 18
0
 public SQLServerCommand(SQLServerConnection conn, string cmd, params SqlParameter[] parameters)
 {
     if (parameters is not null)
     {
         this.Parameters = new List <SqlParameter>(parameters);
     }
     CommandText = cmd;
     _conn       = conn;
 }
Ejemplo n.º 19
0
        public void Delete(SQLServerConnection con)
        {
            var products = con.Table <Product> ().ToList();

            foreach (Product product in products)
            {
                con.Delete(product);
            }
        }
Ejemplo n.º 20
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            //We set the username input you type and set it to passingUsername
            passingUsername = loginInput.Text;
            //If statement where String Input Cannot be null or empty
            if (!string.IsNullOrEmpty(loginInput.Text) &&
                !string.IsNullOrEmpty(passwordInput.Text))
            {
                var mySql = string.Empty;


                mySql += "SELECT * FROM Users ";                        //To Select all attributes from the User Table
                mySql += "WHERE username ='******' ";  //Where username is the input
                //mySQL += "WHERE username = '******' ";
                mySql += "AND password = '******'"; //AND the password Input
                                                                        //mySQL += "AND password = '******'";

                //Using helps dispose of null connection
                var userData = SQLServerConnection.ExecuteSql(mySql);
                if (userData.Rows.Count > 0)
                {
                    if (loginInput.Text == "admin")     //Execute AdminViewPage.cs
                    {
                        loginInput.Clear();
                        passwordInput.Clear();
                        var addPage = new AdminViewForm(); // Initialize LoginForm to a value
                        this.Hide();                       // First need to hide main page
                        addPage.ShowDialog();              //Enable you to go back to Login Page Form
                        this.loginInput.Select();
                    }
                    else
                    {
                        loginInput.Clear();
                        passwordInput.Clear();
                        var studentPage = new StudentViewForm(); // Initialize LoginForm to a value
                        this.Hide();                             // First need to hide main page
                        studentPage.ShowDialog();                //Enable you to go back to Login Page Form
                        this.loginInput.Select();
                    }
                }
                else
                {
                    MessageBox.Show("Wrong Username or Password", "Please Try Again",
                                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    loginInput.Focus();
                    loginInput.SelectAll();
                }
            }

            else
            {
                MessageBox.Show("Please enter a username and password.", "Try Again",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                loginInput.Select();
            }
        }
Ejemplo n.º 21
0
        public void Update(SQLServerConnection con)
        {
            var products = con.Table <Product> ().ToList();

            foreach (Product product in products)
            {
                product.Name += " Updated";
                con.Update(product);
            }
        }
Ejemplo n.º 22
0
        public void UseDbConnection()
        {
            var sqlserver = new SQLServerConnection("database=bd;uid=root;pwd=pass");

            sqlserver.Open();
            sqlserver.Close();
            var orcale = new OracleConnection("a random connection string for oracle");

            orcale.Open();
            orcale.Close();
        }
Ejemplo n.º 23
0
 public static void DeleteItem(SqlConnection SQLconn, int FoodID)
 {
     using (SqlCommand command = new SqlCommand("dbo.DeleteFood", SQLconn))
     {
         command.CommandType = CommandType.StoredProcedure;
         command.Parameters.Add("@IDStall", SqlDbType.Int).Value = FoodID;
         SQLconn.Open();
         command.ExecuteNonQuery();
     }
     SQLServerConnection.CloseSQLConnection(SQLconn);
 }
Ejemplo n.º 24
0
        private void Dispose(bool disposing)
        {
            var s = Statement;

            Statement  = NullStatement;
            Connection = null;
            if (s != NullStatement)
            {
                SQLite3.Finalize(s);
            }
        }
Ejemplo n.º 25
0
 internal bool CheckTriggers(SQLServerConnection Connection)
 {
     foreach (TableMapping map in
              this.Tables
              .Select(d => d.Value.ForSqlServer())
              .Where(x => x.SyncDirection == SyncDirection.Download || x.SyncDirection == SyncDirection.TwoWay))
     {
         Trigger.CheckTrigger(Connection, map, Daemon.Current.DaemonConfig.DbVersion);
         InitTableAttribute.Find(map.MappedType)?.Execute(Connection);
     }
     return(true);
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Dapperのサンプルコード
        /// </summary>
        public void FirstDapper()
        {
            SQLServerConnection.Open();

            var result = SQLServerConnection.Query <HouseholdAccount>(@"SELECT * FROM HOUSEHOLDACCOUNT");

            result.ForEach(x =>
            {
                Console.WriteLine($"Id={x.Id} Item={x.Item} Date={x.Date}");
            });

            SQLServerConnection.Close();
        }
 public static void InitializeConnection(DataBaseType db)
 {
     if (db == DataBaseType.SQLServer)
     {
         SQLServerConnection SQLServer = new SQLServerConnection();
         Connection = SQLServer;
     }
     else if (db == DataBaseType.MySQL)
     {
         MySQLConnection mySQL = new MySQLConnection();
         Connection = mySQL;
     }
 }
Ejemplo n.º 28
0
        //Update Previous
        public void updatePrevious()
        {
            AnnouncementData.wasPreviousButtonClicked = true;
            if (AnnouncementData.arrLength > 1)
            {
                --AnnouncementData.arrLength;
            }
            SqlDataReader reader;
            SqlCommand    cmd = SQLServerConnection.initializeSqlCommand("Select event_desc From Announcement where event_id=@id");

            SqlParameter param = new SqlParameter();

            param.ParameterName = "@id";
            param.Value         = AnnouncementData.arrLength;
            cmd.Parameters.Add(param);

            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                notificationDetails.Text = (reader["event_desc"].ToString());
            }
            cmd.Parameters.Clear(); reader.Close();


            cmd   = SQLServerConnection.initializeSqlCommand("select date_created from Announcement where event_id=@id");
            param = new SqlParameter();
            param.ParameterName = "@id";
            param.Value         = AnnouncementData.arrLength;
            cmd.Parameters.Add(param);

            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                dateLabel.Content = (reader["date_created"].ToString());
            }
            cmd.Parameters.Clear(); reader.Close();

            cmd   = SQLServerConnection.initializeSqlCommand("select event_heading from Announcement where event_id=@id");
            param = new SqlParameter();
            param.ParameterName = "@id";
            param.Value         = AnnouncementData.arrLength;
            cmd.Parameters.Add(param);

            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                notificationLabel.Content = (reader["event_heading"].ToString());
            }
            cmd.Parameters.Clear(); reader.Close();
            SQLServerConnection.closeConnection();
        }
Ejemplo n.º 29
0
        public PeopleController()
        {
            //people.Add(new Person { FirstName = "Tim", LastName = "Corey", Id = 1 });
            //people.Add(new Person { FirstName = "Sue", LastName = "Storm", Id = 2 });
            //people.Add(new Person { FirstName = "Audrey", LastName = "Jenkins", Id = 3 });
            //people.Add(new Person { FirstName = "Billy", LastName = "Peterson", Id = 4 });
            //people.Add(new Person { FirstName = "John", LastName = "Johnson", Id = 5 });
            //people.Add(new Person { FirstName = "George", LastName = "Wisley", Id = 6 });
            //people.Add(new Person { FirstName = "Alex", LastName = "Granger", Id = 7 });
            //people.Add(new Person { FirstName = "Stan", LastName = "Potter", Id = 8 });
            //people.Add(new Person { FirstName = "Stewy", LastName = "Baggings", Id = 9 });

            people = SQLServerConnection.GetPeople();
        }
Ejemplo n.º 30
0
        //关系数据库导航栏双击事件
        private void ucNaviRDB_TreeList_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                TreeList        tree = sender as TreeList;
                TreeListHitInfo hi   = tree.CalcHitInfo(tree.PointToClient(Control.MousePosition));
                if (hi.Node != null)
                {
                    string nodeName = (string)hi.Node["TABLE_NAME"];
                    //如果已经有这个tabPage
                    XtraTabPage ifTabPage = ComponentOperator.IfHasTabPage(nodeName, this.xtraTabControl_Main);
                    if (ifTabPage != null)
                    {
                        this.xtraTabControl_Main.SelectedTabPage = ifTabPage;
                        return;
                    }
                    //如果不包含该TabPage,则新建
                    DataTable dt = SQLServerConnection.GetDataByTableName(nodeName);
                    if (dt == null)
                    {
                        MessageBox.Show("获取数据失败。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    //表格控件
                    SpreadsheetControl ssc      = new SpreadsheetControl();
                    IWorkbook          workbook = ssc.Document;
                    workbook.BeginUpdate();
                    Worksheet worksheet = workbook.Worksheets[0];
                    worksheet.Name = nodeName;
                    worksheet.Import(dt, true, 0, 0);        //import方法需要添加DevExpress.Docs命名空间
                    workbook.EndUpdate();
                    //TabPage
                    XtraTabPage xtp = new XtraTabPage();
                    xtp.Text = nodeName;
                    xtp.Controls.Add(ssc);
                    ssc.Dock = DockStyle.Fill;
                    this.xtraTabControl_Main.TabPages.Add(xtp);
                    this.xtraTabControl_Main.SelectedTabPage = xtp;

                    ssc.Refresh();
                    xtp.Refresh();
                    this.xtraTabControl_Main.Refresh();
                    this.Refresh();
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            IDBConnection<SqlConnection> sqlServerConnection = new SQLServerConnection();
            var sqlServerDatabase = sqlServerConnection.GetDatabase("");
            var sqlServerMapper = new SQLServerMapper<Client, DataSet>();

            var sqlClientBL = GenericBLFactory<Client, Guid, IList<FilterQuery>, DataSet, SqlConnection>.Create(sqlServerConnection, "", "", sqlServerMapper);
            sqlClientBL.GetById(new Guid());
            //var sqlServerRepo = new SQLServerRepository<Client>("", null);
            //sqlServerRepo.GetById("5");

            string databaseName = "test";
            string clientDocument = "client";
            string employeeDocument = "employee";

            // IoC configuration
            var containerBuilder = new ContainerBuilder();
            IConfigIoC manager = new IoCManager(containerBuilder);
            manager.Configure();
            IContainer builder = containerBuilder.Build();

            var dbConnection = builder.Resolve<IDBConnection<IMongoDatabase>>();

            //Connection
            dbConnection.OpenConnection();
            IMongoDatabase mongoDatabase = dbConnection.GetDatabase(databaseName);

            //ClientBL
            var clientMongoMapper = new MongoMapper<Client, BsonDocument>();
            var clientBL = GenericBLFactory<Client, string, IList<FilterQuery>, BsonDocument, IMongoDatabase>.Create(dbConnection, databaseName, clientDocument, clientMongoMapper);
            var employeeMongoMapper = new MongoMapper<Employee, BsonDocument>();
            var employeeBL = GenericBLFactory<Employee, string, IList<FilterQuery>, BsonDocument, IMongoDatabase>.Create(dbConnection, databaseName, employeeDocument, employeeMongoMapper);

            //Creation
            var client = new Client("55554", "Joan");
            var employee = new Employee("12", "Joan", "Wolters Kluwers");

            //Insert
            clientBL.Create(client);
            employeeBL.Create(employee);

            //GetById
            var obtainedClient = clientBL.GetById(client.Id);
            Console.WriteLine("Cliente insertado correctamente. Id: {0}, Name: {1}", obtainedClient.Id, obtainedClient.Name);

            var obtainedEmployee = employeeBL.GetById(employee.Id);
            Console.WriteLine("Employee insertado correctamente. Id: {0}, Name: {1}, WorkStation: {2}", obtainedEmployee.Id, obtainedEmployee.Name, obtainedEmployee.WorkStation);
            Console.ReadLine();

            //GetFiltered
            IList<FilterQuery> queryGetFiltered = new List<FilterQuery>();
            queryGetFiltered.Add(new FilterQuery("_id", "55554", "$eq"));
            queryGetFiltered.Add(new FilterQuery("name", "Joan", "$eq"));
            var resultGetFiltered = clientBL.GetFiltered(queryGetFiltered);
            Console.WriteLine("Clientes encontrados:");
            foreach (var oneClient in resultGetFiltered)
            {
                Console.WriteLine("Cliente encontrado: Id: {0}, Name: {1}", oneClient.Id, oneClient.Name);
            }

            IList<FilterQuery> queryGetFiltered2 = new List<FilterQuery>();
            queryGetFiltered2.Add(new FilterQuery("_id", "12", "$eq"));
            queryGetFiltered2.Add(new FilterQuery("workstation", "Wolters Kluwers", "$eq"));
            var resultGetFiltered2 = employeeBL.GetFiltered(queryGetFiltered2);
            Console.WriteLine("Employees encontrados:");
            foreach (var oneEmployee in resultGetFiltered2)
            {
                Console.WriteLine("Employee encontrado Id: {0}, Name: {1}, WorkStation: {2}", oneEmployee.Id, oneEmployee.Name, oneEmployee.WorkStation);
            }

            Console.ReadLine();
        }