private void GetCompleted(object sender, API.ExecuteCompletedEventArgs e) { this.busy.IsBusy = false; models.Clear(); API.Result res = e.Result; if (res.ReturnValue) { API.SearchModel smodel = res.Obj as API.SearchModel; List <API.Book> list = smodel.Result as List <API.Book>; if (list != null) { var books = (from a in list orderby a.PubDate descending select a).ToList(); models.AddRange(books); GridList.Rebind(); } this.page.PageSize = (int)pagesize.Value; string[] data = new string[smodel.AllPages]; //PagedCollectionView pcv = new PagedCollectionView(data); this.page.PageIndexChanged -= page_PageIndexChanged; this.page.Source = data; this.page.PageIndexChanged += page_PageIndexChanged; this.page.PageIndex = pageindex; } }
public void GetCompleted(object sender, API.ExecuteCompletedEventArgs e) { this.busy.IsBusy = false; if (e.Error != null) { MessageBox.Show(System.Windows.Application.Current.MainWindow, " 服务器错误\n" + e.Error.Message); return; } models.Clear(); API.Result res = e.Result; if (res.ReturnValue) { API.SearchModel smodel = res.Obj as API.SearchModel; List <API.RoleInfo> list = smodel.Result as List <API.RoleInfo>; models.AddRange(list); GridList.Rebind(); this.page.PageSize = (int)pagesize.Value; string[] data = new string[smodel.AllPages]; this.page.PageIndexChanged -= page_PageIndexChanged; this.page.Source = data; this.page.PageIndexChanged += page_PageIndexChanged; this.page.PageIndex = pageindex; } }
/// <summary> /// Invalidates the result returned by API calls for errors and throws a <see cref="MidiOutputDeviceException"/> if an error occured. /// </summary> /// <param name="result">An <see cref="API.Result"/> value containing the result of the API call.</param> internal static void InvalidateResult(API.Result result) { if (result != API.Result.MULTIMEDIA_SYSTEM_ERROR_NO_ERROR) { throw new MidiOutputDeviceException(result); } }
public void GetCompleted(object sender, API.ExecuteCompletedEventArgs e) { this.busy.IsBusy = false; models.Clear(); API.Result res = e.Result; if (res.ReturnValue) { API.SearchModel smodel = res.Obj as API.SearchModel; List <API.BorowInfo> list = smodel.Result as List <API.BorowInfo>; if (list != null) { foreach (var item in list) { if (string.IsNullOrEmpty(item.Borower)) { item.Borower = item.UserName; } } models.AddRange(list); GridList.Rebind(); } this.page.PageSize = (int)pagesize.Value; string[] data = new string[smodel.AllPages]; //PagedCollectionView pcv = new PagedCollectionView(data); this.page.PageIndexChanged -= page_PageIndexChanged; this.page.Source = data; this.page.PageIndexChanged += page_PageIndexChanged; this.page.PageIndex = pageindex; } }
/// <summary> /// 同步请求 /// </summary> /// <param name="busy"></param> /// <param name="methodid"></param> /// <param name="args"></param> /// <returns></returns> public static API.Result Request(RadBusyIndicator busy, int methodid, List <object> args) { if (busy == null) { busy = new RadBusyIndicator(); } busy.IsBusy = true; if (args == null) { args = new List <object>(); } if (methodid != 1) { if (!Store.IsLogin) { NavigationWindow window = new NavigationWindow(); window.Source = new Uri("Login.xaml", UriKind.Relative); window.Show(); } args.Insert(0, Store.CurrentUser == null ? new API.UserInfo() : Store.CurrentUser); } API.BMSServiceClient client = new API.BMSServiceClient(); client.Open(); API.Result ret = client.Execute(methodid, args); client.Close(); busy.IsBusy = false; return(ret); }
/* Function: Dispose */ protected void Dispose(bool strictRulesApply) { if (handle != IntPtr.Zero) { API.Result closeResult = API.CloseV2(handle); handle = IntPtr.Zero; databaseFile = null; if (strictRulesApply == false && closeResult != API.Result.OK) { throw new Exceptions.UnexpectedResult("Could not close database.", closeResult); } } }
/* Function: Step * Executes the statement until it returns a row or completes. Returns true if it returns a row or false if * there are no more. This also resets the column index used by functions like <NextIntColumn()>. */ public bool Step() { API.Result result = API.Step(statementHandle); columnIndex = 0; if (result == API.Result.Row) { return(true); } else if (result == API.Result.Done) { return(false); } else { throw new Exceptions.UnexpectedResult("Could not step query.", result); } }
/* Function: Reset * Restarts the query from the beginning. Can optionally clear its bindings. */ public void Reset(bool clearBindings) { API.Result result = API.Reset(statementHandle); if (result != API.Result.OK) { throw new Exceptions.UnexpectedResult("Could not reset the query.", result); } if (clearBindings == true) { result = API.ClearBindings(statementHandle); if (result != API.Result.OK) { throw new Exceptions.UnexpectedResult("Could not clear statement bindings.", result); } } }
/* Function: Prepare * Prepares a SQL statement for execution. If values are specified, <BindValues()> is called on them. This * function should only be called by <SQLite.Connection>. */ public void Prepare(IntPtr newConnectionHandle, string statement, params Object[] values) { if (statementHandle != IntPtr.Zero) { throw new Exception("Tried to prepare a query when one already existed."); } connectionHandle = newConnectionHandle; API.Result result = API.PrepareV2(connectionHandle, statement, out statementHandle); if (result != API.Result.OK) { statementHandle = IntPtr.Zero; connectionHandle = IntPtr.Zero; throw new Exceptions.UnexpectedResult("Could not prepare query.", result); } if (values.Length != 0) { BindValues(values); } }
/* Function: Prepare * Prepares a SQL statement for execution. If values are specified, <BindValues()> is called on them. This * function should only be called by <SQLite.Connection>. */ public void Prepare(Connection connection, string statement, params Object[] values) { if (statementHandle != IntPtr.Zero) { throw new Exception("Tried to prepare a query when one already existed."); } this.connection = connection; API.Result result = API.PrepareV2(connection.Handle, statement, out statementHandle); if (result != API.Result.OK) { statementHandle = IntPtr.Zero; string errorMessage = "Could not prepare query."; // See if we ran afoul of any limits to make the error message more meaningful // Using SQLite.API.Limit() here causes memory protection errors, which is why we need to get it in the // Connection object and reference that here instead. int sqlByteLength; #if SQLITE_UTF16 sqlByteLength = System.Text.Encoding.Unicode.GetByteCount(statement); #elif SQLITE_UTF8 sqlByteLength = System.Text.Encoding.UTF8.GetByteCount(statement); #else throw new Exception("Did not define SQLITE_UTF8 or SQLITE_UTF16"); #endif int valueCount = (values == null ? 0 : values.Length); if (sqlByteLength > connection.StatementByteLengthLimit && valueCount > connection.ArgumentLimit) { errorMessage += " Statement is too long (byte count: " + sqlByteLength + ", limit: " + connection.StatementByteLengthLimit + ") and " + "has too many arguments (count: " + valueCount + ", limit: " + connection.ArgumentLimit + ")."; } else if (sqlByteLength > connection.StatementByteLengthLimit) { errorMessage += " Statement is too long (byte count: " + sqlByteLength + ", limit: " + connection.StatementByteLengthLimit + ")."; } else if (valueCount > connection.ArgumentLimit) { errorMessage += " Query has too many arguments (count: " + valueCount + ", limit: " + connection.ArgumentLimit + ")."; } var exception = new Exceptions.UnexpectedResult(errorMessage, result); exception.AddNaturalDocsQuery(statement, values); connection = null; throw exception; } if (values != null && values.Length != 0) { BindValues(values); } }
/* Function: Open * * Opens a connection to a database file, possibly creating one if necessary. Throws an exception if it fails. * * Parameters: * * filename - The <Path> of the file to open. * createIfDoesntExist - If true will create the file if it doesn't exist already. */ public void Open(Path filename, bool createIfDoesntExist) { if (IsOpen) { throw new Exception("Tried to open a database connection while the object already had one open."); } // NoMutex has support for multithreading but connections are not serialized. Since we're not going to be sharing connections // and queries between threads, we don't need serialization. API.OpenOption options = API.OpenOption.ReadWrite | API.OpenOption.NoMutex; if (createIfDoesntExist) { options |= API.OpenOption.Create; } API.Result sqliteResult = API.OpenV2(filename, out handle, options); databaseFile = filename; try { if (sqliteResult != API.Result.OK) { throw new Exceptions.UnexpectedResult("Could not open " + (createIfDoesntExist ? "or create " : "") + "database connection to " + filename, sqliteResult); } // Don't check the result since it's not a big deal if this fails. API.ExtendedResultCodes(handle, true); // Even with proper locking it's possible for queries to return Busy, even when all the threads are only reading. Alas. API.BusyTimeout(handle, BusyTimeoutInMS); // No point in using SQLite's case-insensitivity since it only applies to ASCII characters. Execute("PRAGMA case_sensitive_like = 1"); // This allows SQLite to support transactions but keeps the rollback journal in memory instead of on disk. Corruption // caused by a crash isn't a concern because the database is expendable and Natural Docs would rebuild everything the // next time it's run anyway. We'd rather have the performance increase from the lack of disk access. Execute("PRAGMA journal_mode = MEMORY"); // Make any new databases consistent with the API. It will work even with a mismatch, but it will perform better if it's consistent. #if SQLITE_UTF16 Execute("PRAGMA encoding = \"UTF-16\""); #elif SQLITE_UTF8 Execute("PRAGMA encoding = \"UTF-8\""); #else throw new Exception("Did not define SQLITE_UTF8 or SQLITE_UTF16"); #endif // Not turning this off means SQLite will force the operating system to flush the disk cache for the database file at various // points. This means the program will have to pause while the OS commits all changes to disk instead of just counting on // the reliability of the OS's disk cache like almost every other program does. The only corruption this could prevent is when // the entire OS crashes while database writes are still in its cache; just the program crashing is already covered. That level // of paranoia is unnecessary here, and it's especially slow on Linux because it usually can't flush the cache for an individual // file, only the entire filesystem. This cropped up in Firefox: http://shaver.off.net/diary/2008/05/25/fsyncers-and-curveballs/ // or just Google "firefox fsync sqlite". Execute("PRAGMA synchronous = OFF"); } catch { // We have to close the handle even if OpenV2() failed, according to the API. API.CloseV2(handle); handle = IntPtr.Zero; databaseFile = null; throw; } }
/// <summary> /// Creates a new <see cref="MidiDeviceException"/> with the specified error code. /// </summary> /// <param name="errorCode">An <see cref="API.Result"/> value specifying the error code.</param> public MidiDeviceException(API.Result errorCode) { this.ErrorCode = (int)errorCode; }
private void LoginCompleted(object sender, API.ExecuteCompletedEventArgs e) { this.busy.IsBusy = false; if (e.Result.ReturnValue) { API.UserInfo user = e.Result.Obj as API.UserInfo; IntPtr p = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(this.pwd.SecurePassword); // 使用.NET内部算法把IntPtr指向处的字符集合转换成字符串 string password = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(p); if (user.Pwd == Security.GetMD5_32(password)) { Store.CurrentUser = user; Store.IsLogin = true; Store.CurrentRole = e.Result.Arr[0] as API.RoleInfo; API.Result result = RequestHelper.Request(this.busy, (int)MethodType.GetTypeInfoList, new List <object>() { }); if (result.ReturnValue) { List <BMS.API.TypeInfo> list = result.Obj as List <BMS.API.TypeInfo>; Store.TypeInfos.AddRange(list); } API.Result result2 = RequestHelper.Request(this.busy, (int)MethodType.GetMenuInfoList, new List <object>() { }); if (result2.ReturnValue) { List <BMS.API.MenuInfo> list = result2.Obj as List <BMS.API.MenuInfo>; Store.MenuInfos.AddRange(list); } //获取所有用户 API.Result result3 = RequestHelper.Request(this.busy, (int)MethodType.GetAllUsers, new List <object>() { }); if (result3.ReturnValue) { List <BMS.API.UserInfo> list = result3.Obj as List <BMS.API.UserInfo>; Store.UserInfos.AddRange(list); } //NavigationWindow window = new NavigationWindow(); //window.Source = new Uri("Main.xaml", UriKind.Relative); //window.WindowStartupLocation = WindowStartupLocation.CenterScreen; //window.Show(); Main m = new Main(); m.Show(); this.Close(); } else { errorMsg.Text = "密码错误!"; Tool.PlayForegAnimation(errorMsg); } } else { errorMsg.Text = e.Result.Message; Tool.PlayForegAnimation(errorMsg); } }
/// <summary> /// Creates a new <see cref="MidiOutputDeviceException"/> with the specified error code. /// </summary> /// <param name="errorCode">A <see cref="API.Result"/> value specifying the error code.</param> public MidiOutputDeviceException(API.Result errorCode) : base(errorCode) { API.GetMidiOutputDeviceErrorText(errorCode, _Buffer); }
private void add_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(position.Text)) { Tool.PlayBackgAnimation(position); return; } if (string.IsNullOrEmpty(serialNum.Text)) { Tool.PlayBackgAnimation(serialNum); return; } if (string.IsNullOrEmpty(bookName.Text)) { Tool.PlayBackgAnimation(bookName); return; } if (string.IsNullOrEmpty(author.Text)) { Tool.PlayBackgAnimation(author); return; } if (type.SelectedIndex == -1) { Tool.PlayBackgAnimation(type); return; } if (price.Value == 0) { Tool.PlayBackgAnimation(price); return; } if (string.IsNullOrEmpty(publisher.Text)) { Tool.PlayBackgAnimation(publisher); return; } if (string.IsNullOrEmpty(pubDate.DateTimeText) || pubDate.SelectedDate == null) { Tool.PlayBackgAnimation(pubDate); return; } API.Book b = new API.Book(); b.BAuthor = author.Text.Trim(); b.BookName = bookName.Text.Trim(); b.OutLine = outline.Text.Trim(); b.SMPosition = position.Text.Trim(); b.BPrice = (double)price.Value; b.Publisher = publisher.Text; b.PubDate = (DateTime)pubDate.SelectedDate; b.BTypeID = (int)type.SelectedValue; b.SerialNum = serialNum.Text; API.Result ret = RequestHelper.Request(this.busy, (int)MethodType.AddBook, new List <object>() { b }); MessageBox.Show(ret.Message); if (ret.ReturnValue) { Clear(); } }