private static void RecordWithOverridenProperty() { Record2 record21 = new Record2("Lilo", "Mailo"); Console.WriteLine($"Record2: {record21}"); Console.WriteLine(record21.SayHallo()); }
public static void AddField <ResultType, InputType>(this Records.Records Records, System.String ResultFieldName, System.String InputFieldName, System.Func <InputType, InputType, ResultType> Action) { if (Records.Count > 0) { Records.First.Add(ResultFieldName, default(ResultType)); Records.Map((Record1, Record2) => Record2.Add(ResultFieldName, Action(Record1.Get <InputType>(InputFieldName), Record2.Get <InputType>(InputFieldName)))); } }
public void NestedProperty() { var record1 = new Record1(Guid.NewGuid(), "Record 1"); var record2 = new Record2(record1, true); var id = Guid.NewGuid(); var actual = Remute.Default.With(record2, x => x.Record1.Id, id); Assert.AreEqual(id, actual.Record1.Id); }
public void ImmutableDataRecordCannotBeModified() { // --- Arrange var record = new Record2 { Id = 123, DisplayName = "Hello" }; var dataRecord = (IDataRecord)record; // --- Act dataRecord.SignLoaded(); dataRecord.SetImmutable(); record.DisplayName = "Hi"; }
public void ImmutableDataRecordCanBeModifiedDuringLoad() { // --- Act var record = new Record2 { Id = 123, DisplayName = "Hello" }; var dataRecord = (IDataRecord)record; // --- Assert record.Id.ShouldEqual(123); record.DisplayName.ShouldEqual("Hello"); dataRecord.IsModified("Id").ShouldBeFalse(); dataRecord.IsModified("DisplayName").ShouldBeFalse(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (string.IsNullOrEmpty((string)Session["id"])) { //未登录时提示登录 Response.Write("<script type='text/javascript'>alert('" + Resources.Resource.LogInNotice + "');location.href='../ReaderLogin.aspx';</script>"); } //注意这里改成了通过Session获取 string id = (string)Session["id"]; //string id = "111"; if (id == null) { //exception-handler return; } //Database connection test string OLMSDBConnectionString = ConfigurationManager.ConnectionStrings["OLMSDB"].ConnectionString; MySqlConnection OLMSDBConnection = new MySqlConnection(OLMSDBConnectionString); string selectReaderSql = "select * from Readers where ReaderId = ?id;"; string selectBookSql = "select IssueTime, ReturnTime,Title, Fine " + "from IssueRecords, BookBarcodes, Books " + "where BookBarcodes.BookBarcode = IssueRecords.BookBarcode and BookBarcodes.BookId = Books.BookId " + "and IssueRecords.ReaderId = ?reader_id;"; string selectRevervationSql = "select Books.Title, A.ReservingTime, A.ShelfId, C.StackId, A.BookBarcode from BookBarcodes as A, Books, Shelves as C" + " where A.status = 2 and A.ReservingReaderId = ?readerid and Books.BookId = A.BookId and A.ShelfId = C.ShelfId;"; int totalOverdueDays = 0; try { OLMSDBConnection.Open(); MySqlCommand cmd = new MySqlCommand(selectReaderSql, OLMSDBConnection); cmd.Parameters.AddWithValue("?id", id); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if (reader.HasRows) { TextBoxEmail.Text = (string)reader["Email"]; TextBoxName.Text = (string)reader["Name"]; LabelName.Text = "welcome " + (string)reader["Name"] + "!"; TextBoxTelephone.Text = (string)reader["Phone"]; string idNumber = (string)reader["IdNumber"]; idNumber = "**************" + idNumber.Substring(idNumber.Length - 4); TextBoxIDNumber.Text = idNumber; break; } } reader.Close(); MySqlCommand cmd2 = new MySqlCommand(selectBookSql, OLMSDBConnection); cmd2.Parameters.AddWithValue("?reader_id", id); ArrayList issueRecords = new ArrayList(); ArrayList history = new ArrayList(); MySqlDataReader reader2 = cmd2.ExecuteReader(); int flag = 1; while (reader2.Read()) { if (reader2.HasRows) { Record r = new Record(); r.title = (string)reader2["Title"]; DateTime issueTime = (DateTime)reader2["IssueTime"]; DateTime returnTime; TimeSpan d; if (reader2["ReturnTime"] is System.DBNull) { r.returnTime = ""; //获取当前时间 flag = 0; //为归还 DateTime Now = DateTime.Now; d = Now.Subtract(issueTime); } else { try { returnTime = (DateTime)reader2["ReturnTime"]; r.returnTime = returnTime.ToString(); } catch (Exception ex) { returnTime = DateTime.Now; flag = 0; r.returnTime = ""; } d = returnTime.Subtract(issueTime); } int delta = d.Days - 30; if (delta < 0) { r.overdueTime = "0"; } else { r.overdueTime = delta.ToString(); totalOverdueDays = totalOverdueDays + delta; } r.issueTime = issueTime.ToString(); if (reader2["Fine"] is System.DBNull) { r.fine = ""; } else { r.fine = reader2["Fine"].ToString(); } if (flag == 1) { history.Add(r); } else { issueRecords.Add(r); } } } int finePerDay = int.Parse(ConfigurationManager.AppSettings.Get("OverdueFinePerDay")); double totalFine = totalOverdueDays * finePerDay; TextBoxFine.Text = totalFine.ToString(); reader2.Close(); MySqlCommand cmd3 = new MySqlCommand(selectRevervationSql, OLMSDBConnection); cmd3.Parameters.AddWithValue("?readerid", id); ArrayList reversationRecords = new ArrayList(); MySqlDataReader reader3 = cmd3.ExecuteReader(); string ReversationTime = ""; try { ReversationTime = ConfigurationManager.AppSettings.Get("OverdueReservationDuration"); } catch { ReversationTime = ""; } double ReversationTime2 = double.Parse(ReversationTime); while (reader3.Read()) { if (reader3.HasRows) { Record2 r = new Record2(); r.barcode = (string)reader3["BookBarcode"]; r.shelf = reader3.GetString("ShelfId"); r.stack = reader3.GetString("StackId"); r.title = reader3.GetString("Title"); DateTime time = (DateTime)reader3["ReservingTime"]; DateTime nowTime = DateTime.Now; TimeSpan delta = nowTime.Subtract(time); double d = (double)delta.TotalMinutes; r.time = String.Format("{0:F}", ReversationTime2 * 60 - d); reversationRecords.Add(r); } } GridView1.DataSource = issueRecords; GridView1.DataBind(); GridView2.DataSource = reversationRecords; GridView2.DataBind(); GridView3.DataSource = history; GridView3.DataBind(); } catch (MySqlException ex) { //exception-handler Console.WriteLine(ex.Message); } finally { OLMSDBConnection.Close(); } } }
bool Equals(Record2 other) { return(Type == other.Type && string.Equals(Date, other.Date) && string.Equals(Description, other.Description)); }
public override string ToString() { return(IsMatch.ToString() + "\n" + Record1.ToString() + "\n" + Record2.ToString() + "\n"); }