public void Test() { List<Person> list = new List<Person> { new Person { FirstName = "John", LastName = "Smith", Gender = Gender.Male }, new Person { FirstName = "Jane", LastName = "Smith", Gender = Gender.Female } }; using (DbManager db = new DbManager()) { db.BeginTransaction(); // Prepare command. // db .SetSpCommand("Person_Insert", db.CreateParameters(list[0])) ./*[a]*/Prepare/*[/a]*/(); // Insert. // foreach (Person person in list) { db./*[a]*/AssignParameterValues/*[/a]*/(person); db.ExecuteNonQuery(); } // Check the result. // list = db .SetCommand( "SELECT * FROM Person WHERE LastName = @lastName", db.Parameter("@lastName", "Smith")) .ExecuteList<Person>(); Assert.GreaterOrEqual(2, list.Count); // Cleanup. // db .SetCommand( "DELETE FROM Person WHERE LastName = @lastName", db.Parameter("@lastName", "Smith")) .ExecuteNonQuery(); db.CommitTransaction(); } }
static void Main(string[] args) { using (var db = new DbManager()) { db.SetSpCommand(""); // ok db.SetInsertCommand(""); // ok db.SetUpdateCommand(""); // ok db.Prepare(); // ok db.ExecuteNonQuery(); // ok db.SetCommand(""); // ERROR: // error CS0584: Internal compiler error: Object reference not set to an instance of an object // error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement } }
public static void Migrate() { using (DbManager db = new DbManager()) { DbVersion currentVersion = null; int dbVersion = 0; try { List<DbVersion> list = new SqlQuery<DbVersion>(db).SelectAll(); if (list.Count > 0) { currentVersion = list[0]; dbVersion = currentVersion.CurrentValue; } } catch { } Assembly currentAssembly = Assembly.GetCallingAssembly(); var migrateScriptNames = from resourceName in currentAssembly.GetManifestResourceNames() where resourceName.Contains(migrateTemplate) select resourceName; foreach (string scriptName in migrateScriptNames) { Match verMatch = Regex.Match(scriptName, string.Format(@"{0}(\d+)",migrateTemplate)); int version = int.Parse(verMatch.Groups[1].Value); if (verMatch.Success && version > dbVersion) { using (StreamReader reader = new StreamReader(currentAssembly.GetManifestResourceStream(scriptName))) { string allScript = reader.ReadToEnd(); foreach (string command in allScript.Split(new string[] { "----------" }, StringSplitOptions.RemoveEmptyEntries)) { db.SetCommand(command); db.ExecuteNonQuery(); } if (null != currentVersion) { currentVersion.CurrentValue = version; new SqlQuery<DbVersion>(db).Update(currentVersion); } } } } } }
protected override void OnStartup(StartupEventArgs e) { EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus)); EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotMouseCaptureEvent, new RoutedEventHandler(TextBox_GotMouseCapture)); base.OnStartup(e); try { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); App.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; if (Keyboard.Modifiers == ModifierKeys.Shift) { new SettingsWindow().ShowDialog(); } string connectionString = string.Format(@"DataSource={0};Database=d:\ProfStor\SKLAD.GDB;User=SYSDBA;Password=masterkey;Dialect=3;Charset=win1251", Utils.Config.AppSettings.Settings["Server"].Value); if(!ApplicationDeployment.IsNetworkDeployed) connectionString = string.Format(@"DataBase=c:\Users\user\Documents\Visual Studio 2010\Projects\BoginyaJournal\bin\Debug\SKLAD.GDB;User=SYSDBA;Password=masterkey;Dialect=3;Charset=win1251"); BLToolkit.Data.DbManager.AddConnectionString("Fdp", "Sklad", connectionString); BLToolkit.Data.DbManager.AddDataProvider(new BLToolkit.Data.DataProvider.FdpDataProvider()); //checkin connection using (DbManager db = new DbManager()) { db.SetCommand("select * from users"); db.ExecuteNonQuery(); } DbMigration.DBMigration.Migrate(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error",MessageBoxButton.OK,MessageBoxImage.Error); System.Diagnostics.Process.GetCurrentProcess().Kill(); } //sending mail new Thread(new ThreadStart(()=> { for (var i = 0; i < 3; i++) { try { //Utils.SendMail(Utils.GetNISTDate(true).AddDays(-1)); break; } catch{ Thread.Sleep(10000); } } } )).Start(); Login login = new Login(); login.ShowDialog(); if (login.DialogResult == null || login.DialogResult == false) { Application.Current.Shutdown(); } }
public void SaveContract(CustomerCommissionRateListAccessor commissionList, CustomerPayableListAccessor payableList) { using (DbManager db = new DbManager()) { try { db.Command.CommandText = string.Format(@"delete from CUSTOMER_COMMISSION_TBL where CUSTCODE = '{0}'", outletRefLink.CustomerCode); db.ExecuteNonQuery(); foreach (CustomerCommissionRate commrate in commissionList.AllCommission) { if (string.IsNullOrEmpty(commrate.CustomerCode)) commrate.CustomerCode = outletRefLink.CustomerCode; db.Command.CommandText = string.Format(@"insert into CUSTOMER_COMMISSION_TBL values('{0}','{1}','{2}',{3})", commrate.CustomerCode, commrate.SalesType, commrate.FieldType, commrate.FieldValue); db.ExecuteNonQuery(); } db.Command.CommandText = string.Format(@"delete from CUSTOMER_PAYABLE_TBL where CUSTCODE = '{0}'", outletRefLink.CustomerCode); db.ExecuteNonQuery(); foreach (CustomerPayableClass payable in payableList.AllPayables) { if (string.IsNullOrEmpty(payable.CustomerCode)) payable.CustomerCode = outletRefLink.CustomerCode; db.Command.CommandText = string.Format(@"insert into CUSTOMER_PAYABLE_TBL values('{0}','{1}',{2})", payable.CustomerCode, payable.PayableCode, payable.PayableAmount); db.ExecuteNonQuery(); } } catch (Exception except) { throw new System.ArgumentException(except.Message); } } }