public string Save(LoanParty loanParty) { if (loanGateway.Insert(loanParty) > 0) { return("Saved Successfully!!"); } else { return("Could Not save data in DataBase"); } }
public int Insert(LoanParty loanParty) { SqlConnection connection = new SqlConnection(connectionString); string query = "INSERT INTO tbl_loan VALUES('" + loanParty.LoanCode + "','" + loanParty.LoanName + "','" + loanParty.Remarks + "')"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return(rowAffected); }
protected void saveButton_Click(object sender, EventArgs e) { LoanParty loanParty = new LoanParty(); loanParty.LoanCode = int.Parse(loanCodeTextBox.Text); loanParty.LoanName = loanNameTextBox.Text; loanParty.Remarks = remarksTextArea.InnerText; if (loanCodeTextBox.Text == "" || loanNameTextBox.Text == "" || remarksTextArea.InnerText == "") { message.InnerText = "All Fields are Required!!"; } else { message.InnerText = loanManager.Save(loanParty); } }
private string LoadNextLoanCode() { LoanParty lp = loanManager.GetNextLoanCode(); string lpCode = lp.LoanCode.ToString(); int count; if (lpCode == null) { count = 1; } else { // count = (lpCode[0] - '0')*10 + (lpCode[5] - '0') + 1; count = (lpCode[0] - '0') + 1; } string nextCode = "" + count.ToString("0"); return(nextCode); }
public LoanParty GetNextLoanCode() { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT TOP 1 * FROM tbl_loan ORDER BY id DESC"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); LoanParty loanParty = new LoanParty(); while (reader.Read()) { loanParty.LoanPartyId = int.Parse(reader["id"].ToString()); loanParty.LoanCode = Convert.ToInt32(reader["loan_code"].ToString()); } reader.Close(); connection.Close(); return(loanParty); }