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