Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
 public static ExpenseCode SaveEntity(ExpenseCode expensecode)
 {
     if (expensecode.ExCodeID > 0)
     {
         return(UpdateEntity(expensecode));
     }
     else
     {
         return(AddEntity(expensecode));
     }
 }
Example #5
0
 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();
         }
     }
 }
Example #6
0
        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()));
            }
        }
Example #7
0
        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.");
        }
Example #8
0
 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);
 }
Example #9
0
        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;
            }
        }
Example #10
0
        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);
        }
Example #11
0
        private void SetupBindings()
        {
            BindingList <ExpenseCode> buyerList = new BindingList <ExpenseCode>(ExpenseCode.GetEntityList());

            expensecodeBindingSource.DataSource = buyerList;
        }
Example #12
0
 public bool BeginsWithOrderID(ExpenseCode expensecode)
 {
     return(expensecode.ExCodeID.ToString().StartsWith(ExCodeID.ToString()));
 }
Example #13
0
 public bool MatchesOrderID(ExpenseCode expensecode)
 {
     return(expensecode.ExCodeID == ExCodeID);
 }