private void PopulateFields(int id) { newEntity = new PayableEntity(); newEntity = newService.GetOne(id); txtLoanId.Text = newEntity.LoanId.ToString(); txtAmount.Text = "Php " + newEntity.Amount.ToString(); txtDate.Text = newEntity.PayDate.ToString("yyyy-MM-dd"); txtNotes.Text = newEntity.Notes; ddlStatus.SelectedValue = newEntity.Status.ToString(); if (newEntity.Status == 1) { //ddlStatus.Enabled = false; } }
private PayableEntity SetData(DataRow oRow) { try { PayableEntity ent = new PayableEntity(); ent.ID = Convert.ToInt32(oRow["id"]); ent.Amount = Convert.ToDecimal(oRow["amount"]); ent.LoanId = Convert.ToInt32(oRow["loan_id"]); ent.PayDate = Convert.ToDateTime(oRow["date"]); ent.Notes = oRow["notes"].ToString(); ent.Status = Convert.ToInt32(oRow["status"]); return ent; } catch (Exception ex) { throw ex; } }
public void Save(ActionType type, PayableEntity ent) { try { using (Database db = new Database(GlobalObjects.CONNECTION_STRING)) { db.Open(); int ret = 0; int typ = (int)type; string sql = "SavePayable"; string[] asParams; DbType[] atParamTypes; object[] aoValues; asParams = new string[] { "@actiontype", "@id", "@date", "@notes", "@status", "@createdby", "@createddate", "@updatedby", "@updateddate"}; atParamTypes = new DbType[] { DbType.Int16, DbType.Int32, DbType.Date, DbType.String, DbType.Int32, DbType.String, DbType.DateTime, DbType.String, DbType.DateTime }; aoValues = new object[] { typ, ent.ID, ent.PayDate, ent.Notes, ent.Status, appUsr.UserName, DateTime.Now, appUsr.UserName, DateTime.Now }; db.ExecuteCommandNonQuery(sql, asParams, atParamTypes, aoValues, out ret, CommandTypeEnum.StoredProcedure); } } catch (Exception ex) { throw ex; } }
public PayableEntity GetOne(int userId) { try { using (Database db = new Database(GlobalObjects.CONNECTION_STRING)) { db.Open(); string sql; int ret = 0; DataTable oTable = new DataTable(); sql = "GetPayable"; db.ExecuteCommandReader(sql, new string[] { "@id" }, new DbType[] { DbType.Int32 }, new object[] { userId }, out ret, ref oTable, CommandTypeEnum.StoredProcedure); PayableEntity user = new PayableEntity(); if (oTable.Rows.Count > 0) { DataRow oRow = oTable.Rows[0]; user = SetData(oRow); } return user; } } catch (Exception ex) { throw ex; } }
private void Update() { newEntity = new PayableEntity(); newEntity.ID = id; newEntity.Notes = txtNotes.Text; newEntity.Status = Convert.ToInt32(ddlStatus.SelectedValue); newEntity.PayDate = Convert.ToDateTime(txtDate.Text); newService.Save(ActionType.Update, newEntity); Response.Redirect(string.Format("ViewLoan.aspx?id={0}", Utility.EncryptQueryString(HttpUtility.UrlEncode(txtLoanId.Text)))); }