public static ExpenseCode GetEntity(decimal buyerID) { ExpenseCode expensecode = null; using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_ExpenseCode_Get"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ExCodeID", buyerID); cn.Open(); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (rdr.HasRows) { rdr.Read(); expensecode = FillExpenseCode(rdr); } if (!rdr.IsClosed) { rdr.Close(); } } } return(expensecode); }
public static List <ExpenseCode> GetEntityList() { List <ExpenseCode> buyerList = new List <ExpenseCode>(); using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_ExpenseCode_GetList"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cn.Open(); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (rdr.Read()) { ExpenseCode expensecode = FillExpenseCode(rdr); buyerList.Add(expensecode); } if (!rdr.IsClosed) { rdr.Close(); } } } return(buyerList); }
private static ExpenseCode FillExpenseCode(SqlDataReader rdr) { ExpenseCode expensecode = new ExpenseCode(); expensecode.ExCodeID = Convert.ToDecimal(rdr["ExCodeID"]); expensecode.expenseCode = rdr["ExpenseCode"].ToString(); expensecode.ExDescription = rdr["ExDescription"].ToString(); return(expensecode); }
public static ExpenseCode SaveEntity(ExpenseCode expensecode) { if (expensecode.ExCodeID > 0) { return(UpdateEntity(expensecode)); } else { return(AddEntity(expensecode)); } }
public static void DeleteEntity(ExpenseCode expensecode) { using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_ExpenseCode_Delete"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ExCodeID", expensecode.ExCodeID); cn.Open(); cmd.ExecuteNonQuery(); } } }
private void Delete() { ExpenseCode expensecode = expensecodeBindingSource.Current as ExpenseCode; // (BindingList<ExpenseCode>)userBindingSource.DataSource; //ExpenseCode expensecode = OrderList[userBindingSource.Position]; decimal ExCodeID = expensecode.ExCodeID; DialogResult dlg = MessageBox.Show(string.Format("Are you sure you want to delete Expense Code # {0}?", ExCodeID.ToString())); if (dlg == System.Windows.Forms.DialogResult.OK) { ExpenseCode.DeleteEntity(expensecode); expensecodeBindingSource.RemoveCurrent(); MessageBox.Show(string.Format("Expense Code # {0} was deleted.", ExCodeID.ToString())); } }
private void Save() { expensecodeBindingSource.EndEdit(); ExpenseCode expensecode = expensecodeBindingSource.Current as ExpenseCode; //BindingList<ExpenseCode> OrderList = (BindingList<ExpenseCode>)userBindingSource.DataSource; //ExpenseCode ExpenseCode = OrderList[userBindingSource.Position]; ExpenseCode.SaveEntity(expensecode); BindingList <ExpenseCode> orderList = new BindingList <ExpenseCode>(ExpenseCode.GetEntityList()); expensecodeBindingSource.DataSource = orderList; MessageBox.Show("Expense Code was saved."); }
private static ExpenseCode UpdateEntity(ExpenseCode expensecode) { using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_ExpenseCode_Update"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ExCodeID", expensecode.ExCodeID); cmd.Parameters.AddWithValue("@ExpenseCode", expensecode.expenseCode); cmd.Parameters.AddWithValue("@ExDescription", expensecode.ExDescription); cn.Open(); cmd.ExecuteNonQuery(); } } expensecode = GetEntity(expensecode.ExCodeID); return(expensecode); }
private void toolBtnFindOrderNumber_Click(object sender, EventArgs e) { List <ExpenseCode> orderList = new List <ExpenseCode>(expensecodeBindingSource.DataSource as BindingList <ExpenseCode>); BuyerFilter userFilter = new BuyerFilter(Convert.ToInt32(toolTxtFindOrderNumber.Text)); //Predicate<ExpenseCode> filterByOrderID = new Predicate<ExpenseCode>(orderFilter.MatchesOrderID); Predicate <ExpenseCode> filterByOrderID = new Predicate <ExpenseCode>(userFilter.BeginsWithOrderID); ExpenseCode expensecode = orderList.Find(filterByOrderID); if (expensecode == null) { MessageBox.Show("No matching Expense Code found", "Not Found", MessageBoxButtons.OK); } else { int index = expensecodeBindingSource.IndexOf(expensecode); expensecodeBindingSource.Position = index; } }
private static ExpenseCode AddEntity(ExpenseCode expensecode) { int ExCodeID = 0; using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_ExpenseCode_Add"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ExpenseCode", expensecode.expenseCode); cmd.Parameters.AddWithValue("@ExDescription", expensecode.ExDescription); cmd.Parameters.Add(new SqlParameter("@ExCodeID", SqlDbType.Int)); cmd.Parameters["@ExCodeID"].Direction = ParameterDirection.Output; cn.Open(); cmd.ExecuteNonQuery(); ExCodeID = Convert.ToInt32(cmd.Parameters["@ExCodeID"].Value); } expensecode = GetEntity(ExCodeID); } return(expensecode); }
private void SetupBindings() { BindingList <ExpenseCode> buyerList = new BindingList <ExpenseCode>(ExpenseCode.GetEntityList()); expensecodeBindingSource.DataSource = buyerList; }
public bool BeginsWithOrderID(ExpenseCode expensecode) { return(expensecode.ExCodeID.ToString().StartsWith(ExCodeID.ToString())); }
public bool MatchesOrderID(ExpenseCode expensecode) { return(expensecode.ExCodeID == ExCodeID); }