private static JobCharge AddEntity(JobCharge jobcharge) { int CHID = 0; using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_JobCharge_Add"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Job_Code", jobcharge.Job_Code); cmd.Parameters.AddWithValue("@Jobno", jobcharge.Jobno); cmd.Parameters.AddWithValue("@Subjobno", jobcharge.Subjobno); cmd.Parameters.AddWithValue("@Jobno_desc", jobcharge.Jobno_desc); cmd.Parameters.AddWithValue("@Subjobno_desc", jobcharge.Subjobno_desc); cmd.Parameters.Add(new SqlParameter("@CHID", SqlDbType.Int)); cmd.Parameters["@CHID"].Direction = ParameterDirection.Output; cn.Open(); cmd.ExecuteNonQuery(); CHID = Convert.ToInt32(cmd.Parameters["@CHID"].Value); } jobcharge = GetEntity(CHID); } return(jobcharge); }
public static JobCharge GetEntity(decimal jobchargeID) { JobCharge jobcharge = null; using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_JobCharge_Get"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CHID", jobchargeID); cn.Open(); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (rdr.HasRows) { rdr.Read(); jobcharge = FillJobCharge(rdr); } if (!rdr.IsClosed) { rdr.Close(); } } } return(jobcharge); }
public static List <JobCharge> GetEntityList() { List <JobCharge> jobchargeList = new List <JobCharge>(); using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_JobCharge_GetList"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cn.Open(); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (rdr.Read()) { JobCharge jobcharge = FillJobCharge(rdr); jobchargeList.Add(jobcharge); } if (!rdr.IsClosed) { rdr.Close(); } } } return(jobchargeList); }
public static JobCharge SaveEntity(JobCharge jobcharge) { if (jobcharge.CHID > 0) { return(UpdateEntity(jobcharge)); } else { return(AddEntity(jobcharge)); } }
private static JobCharge FillJobCharge(SqlDataReader rdr) { JobCharge jobcharge = new JobCharge(); jobcharge.CHID = Convert.ToDecimal(rdr["CHID"]); jobcharge.Job_Code = rdr["Job_Code"].ToString(); jobcharge.Jobno = rdr["Jobno"].ToString(); jobcharge.Subjobno = rdr["Subjobno"].ToString(); jobcharge.Jobno_desc = rdr["Jobno_desc"].ToString(); jobcharge.Subjobno_desc = rdr["Subjobno_desc"].ToString(); return(jobcharge); }
public static void DeleteEntity(JobCharge jobcharge) { using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_JobCharge_Delete"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CHID", jobcharge.CHID); cn.Open(); cmd.ExecuteNonQuery(); } } }
private void Delete() { JobCharge jobcharge = jobchargeBindingSource.Current as JobCharge; // (BindingList<JobCharge>)userBindingSource.DataSource; //JobCharge jobcharge = OrderList[userBindingSource.Position]; decimal CHID = jobcharge.CHID; DialogResult dlg = MessageBox.Show(string.Format("Are you sure you want to delete JobCharge # {0}?", CHID.ToString())); if (dlg == System.Windows.Forms.DialogResult.OK) { JobCharge.DeleteEntity(jobcharge); jobchargeBindingSource.RemoveCurrent(); MessageBox.Show(string.Format("JobCharge # {0} was deleted.", CHID.ToString())); } }
private void Save() { jobchargeBindingSource.EndEdit(); JobCharge jobcharge = jobchargeBindingSource.Current as JobCharge; //BindingList<JobCharge> OrderList = (BindingList<JobCharge>)userBindingSource.DataSource; //JobCharge JobCharge = OrderList[userBindingSource.Position]; JobCharge.SaveEntity(jobcharge); BindingList <JobCharge> orderList = new BindingList <JobCharge>(JobCharge.GetEntityList()); jobchargeBindingSource.DataSource = orderList; MessageBox.Show("JobCharge was saved."); }
private void toolBtnFindOrderNumber_Click(object sender, EventArgs e) { List <JobCharge> orderList = new List <JobCharge>(jobchargeBindingSource.DataSource as BindingList <JobCharge>); BuyerFilter userFilter = new BuyerFilter(Convert.ToInt32(toolTxtFindOrderNumber.Text)); //Predicate<JobCharge> filterByOrderID = new Predicate<JobCharge>(orderFilter.MatchesOrderID); Predicate <JobCharge> filterByOrderID = new Predicate <JobCharge>(userFilter.BeginsWithOrderID); JobCharge jobcharge = orderList.Find(filterByOrderID); if (jobcharge == null) { MessageBox.Show("No matching JobCharge found", "Not Found", MessageBoxButtons.OK); } else { int index = jobchargeBindingSource.IndexOf(jobcharge); jobchargeBindingSource.Position = index; } }
private static JobCharge UpdateEntity(JobCharge jobcharge) { using (SqlConnection cn = new SqlConnection(Common.ConnectionString)) { string proc = "pr_JobCharge_Update"; using (SqlCommand cmd = new SqlCommand(proc, cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CHID", jobcharge.CHID); cmd.Parameters.AddWithValue("@Job_Code", jobcharge.Job_Code); cmd.Parameters.AddWithValue("@Jobno", jobcharge.Jobno); cmd.Parameters.AddWithValue("@Subjobno", jobcharge.Subjobno); cmd.Parameters.AddWithValue("@Jobno_desc", jobcharge.Jobno_desc); cmd.Parameters.AddWithValue("@Subjobno_desc", jobcharge.Subjobno_desc); cn.Open(); cmd.ExecuteNonQuery(); } } jobcharge = GetEntity(jobcharge.CHID); return(jobcharge); }
private void SetupBindings() { BindingList <JobCharge> jobchargeList = new BindingList <JobCharge>(JobCharge.GetEntityList()); jobchargeBindingSource.DataSource = jobchargeList; }
public bool BeginsWithOrderID(JobCharge jobcharge) { return(jobcharge.CHID.ToString().StartsWith(CHID.ToString())); }
public bool MatchesOrderID(JobCharge jobcharge) { return(jobcharge.CHID == CHID); }