public List <circulation> getCirculationList() { //string connectString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["mysqlConnectString"].ToString(); MySqlConnection conn = new MySqlConnection(connectString); string sql = "SELECT id, reader_name, book_id, signal_code, action_time, action_type, book_name, location_name from circulation where is_deleted = 0 order by id desc"; MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader dr; List <circulation> circulationList = new List <circulation>(); try { conn.Open(); dr = cmd.ExecuteReader(); while (dr.Read()) { circulation circulation = new circulation(); circulation.Id = Convert.ToInt32(dr["id"]); circulation.Reader_name = Convert.ToString(dr["reader_name"]); circulation.Book_id = Convert.ToString(dr["book_id"]); circulation.Signal_code = Convert.ToString(dr["signal_code"]); circulation.Action_time = Convert.ToString(dr["action_time"]); circulation.Action_type = Convert.ToString(dr["action_type"]); circulation.Book_name = Convert.ToString(dr["book_name"]); circulation.Location_name = Convert.ToString(dr["location_name"]); circulationList.Add(circulation); } } catch (Exception ex) { Console.WriteLine(ex); } finally { conn.Close(); Console.WriteLine("finally!"); } return(circulationList); }
private void submitBtn_Click(object sender, EventArgs e) { string circpath = @"C:\projects\book_zoned\Database\circulation.txt"; string bookpath = @"C:\projects\book_zoned\Database\books.txt"; string issuepath = @"C:\projects\book_zoned\Database\issued.txt"; if (libcardnoField.Text.Trim() != string.Empty && bookIdField.Text.Trim() != string.Empty && bookNameField.Text.Trim() != string.Empty && returnDateField.Text.Trim() != string.Empty) { members m = new members(); circulation c = new circulation(); books b = new books(); string lcn = libcardnoField.Text; string mname = nameField.Text; string bid = bookIdField.Text; string bnm = bookNameField.Text; string rtndate = returnDateField.Text; m.lcn = lcn; m.name = mname; b.bookid = bid; b.bookname = bnm; c.rtndate = rtndate; // finding book issued StreamReader sread = new StreamReader(issuepath); string thisline; string lcn1 = libcardnoField.Text; m.lcn = lcn1; string searchS = m.lcn; bool foundText = false; do { thisline = sread.ReadLine(); if (thisline != null) { foundText = thisline.Contains(searchS); } }while (thisline != null && !foundText); if (foundText) { string[] result = thisline.Split('|'); string issorret = result[1]; string name = result[2]; string lcn2 = result[3]; string bid2 = result[4]; string bname = result[5]; string issdat = result[6]; string retdat = result[7]; DateTime isdt = Convert.ToDateTime(issdat); DateTime rndt = Convert.ToDateTime(rtndate); DateTime returnDate = returnDateField.Value.Date; TimeSpan differnce = returnDate - isdt; int days = differnce.Days; if (days > 15) { fineamt = (days - 15) * 1; } sread.Close(); List <string> circ_line = File.ReadAllLines(circpath).ToList(); string circ_created = "| RETURN | " + m.lcn + " | " + m.name + " | " + b.bookid + " | " + b.bookname + " | " + c.rtndate + " | "; circ_line.Add(circ_created); File.WriteAllLines(circpath, circ_line); dataBox.Text = circ_created; } else { MessageBox.Show("NO RECORD FOUND", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } StreamReader sr = new StreamReader(bookpath); string currentLine; string searchString = b.bookid; bool foundTxt = false; do { currentLine = sr.ReadLine(); if (currentLine != null) { foundTxt = currentLine.Contains(searchString); } }while (currentLine != null && !foundTxt); if (foundTxt) { string[] result = currentLine.Split('|'); string bookid = result[1]; string bookname = result[2]; string author = result[3]; string publication = result[4]; string costprice = result[5]; string counter = result[6]; int add = int.Parse(counter); int sum = add + 1; result[6] = sum.ToString(); // funtion to display fine sr.Close(); List <string> book_line = File.ReadAllLines(bookpath).ToList(); string book_created = "| " + bookid + "|" + bookname + "|" + author + "|" + publication + "|" + costprice + "|" + result[6] + "|"; hideBox.Text = book_created; MessageBox.Show("CONFIRM THE ORDER ONCE"); MessageBox.Show("YOU ARE LATE BY " + fineamt + " NUMBER OF DAYS. FINE AMOUNT IS " + fineamt); } } else { MessageBox.Show("NO BLANK FIELD MUST BE LEFT", "RETRY", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } }
private void submitBtn_Click(object sender, EventArgs e) { if (nameField.Text.Trim() != string.Empty && libcardnoField.Text.Trim() != string.Empty && bookIdField.Text.Trim() != string.Empty && bookNameField.Text.Trim() != string.Empty && issueDateField.Text.Trim() != string.Empty) { books b = new books(); members m = new members(); circulation c = new circulation(); string memberpath = @"C:\projects\book_zoned\Database\members.txt"; string bookpath = @"C:\projects\book_zoned\Database\books.txt"; string circpath = @"C:\projects\book_zoned\Database\circulation.txt"; string issuepath = @"C:\projects\book_zoned\Database\issued.txt"; var lines = File.ReadAllLines(bookpath).Where(arg => !string.IsNullOrWhiteSpace(arg)); File.WriteAllLines(bookpath, lines); if (!File.Exists(circpath)) { File.Create(circpath).Close(); } m.name = nameField.Text; m.lcn = libcardnoField.Text; b.bookid = bookIdField.Text; b.bookname = bookNameField.Text; c.iss = issueDateField.Text; c.rtn = returnDateField.Text; using (StreamReader member_read = new StreamReader(memberpath)) // using1 { string findlib = libcardnoField.Text; string findname = nameField.Text; bool foundText = false; bool foundLib = false; bool foundname = false; string thisline; // find library card number do { thisline = member_read.ReadLine(); if (thisline != null) { foundLib = thisline.Contains(findlib); } } while (thisline != null && !foundLib); if (foundLib) { do { if (thisline != null) { foundname = thisline.Contains(findname); } } while (thisline != null && !foundname); if (foundname) { using (StreamReader book_read = new StreamReader(bookpath)) //using2 { string searchString = bookIdField.Text; b.search = searchString; string currentLine; // int count; do { currentLine = book_read.ReadLine(); if (currentLine != null) { foundText = currentLine.Contains(b.search); } } while (currentLine != null && !foundText); if (foundText) { string[] result = currentLine.Split('|'); string bookid = result[1]; string bookname = result[2]; string author = result[3]; string publication = result[4]; string costprice = result[5]; string counter = result[6]; if (int.Parse(counter) >= 1) { List <string> circ_line = File.ReadAllLines(circpath).ToList(); string circ_created = "| ISSUE | " + m.name + " | " + m.lcn + " | " + b.bookid + " | " + b.bookname + " | " + c.iss + " | " + c.rtn + " | "; circ_line.Add(circ_created); File.WriteAllLines(circpath, circ_line); MessageBox.Show("CONFIRM THE ORDER ONCE"); // inserting book details string searchstring = bookIdField.Text; b.search = searchstring; using (StreamReader read2 = new StreamReader(bookpath)) { bool found = false; string current; int count2; do { current = read2.ReadLine(); if (current != null) { found = current.Contains(b.search); } } while (current != null && !found); if (found) { string[] result2 = currentLine.Split('|'); string bookid2 = result2[1]; string bookname2 = result2[2]; string author2 = result2[3]; string publication2 = result2[4]; string costprice2 = result2[5]; string counter2 = result2[6]; int count3; count2 = int.Parse(counter2); count3 = count2 - 1; result[6] = count3.ToString(); read2.Close(); string insert2 = "| " + bookid2 + " | " + bookname2 + " | " + author2 + " | " + publication2 + " | " + costprice2 + " | " + result[6] + " | "; hideBox.Text = insert2; List <string> issue_line = File.ReadAllLines(issuepath).ToList(); string issue_created = "| ISSUE | " + m.name + " | " + m.lcn + " | " + b.bookid + " | " + b.bookname + " | " + c.iss + " | " + c.rtn + " |"; issue_line.Add(issue_created); File.WriteAllLines(issuepath, issue_line); dataBox.Text = issue_created; } } // end of if (found) //end of entering book details } // end of if (int.Parse(counter) >= 1) else { MessageBox.Show("NO BOOKS AVAILABLE", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } //end if(foundtext) else { MessageBox.Show("BOOK DOES NOT EXIST", "ERROR", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } //else } // end of using (StreamReader sr = new StreamReader(bookpath)) } //if for name else { MessageBox.Show("NAME DOESNT EXIST", "ERROR", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } } else { MessageBox.Show("LIBRARY CARD DOESNT EXIST", "ERROR", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } } // end of using (StreamReader member_read = new StreamReader(memberpath)) } // string validation else { MessageBox.Show("NO FIELDS SHOULD BE LEFT BLANK", "ERROR", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } }