private void LoadPayPeriods(CompPlanLib.Globals.performance_target_level level) { DateTime current_date = DateTime.Now; // Going to modify this so that for sales consultants we can have current pay period recalcs int start_day = (level == CompPlanLib.Globals.performance_target_level.Employee) ? (current_date.Day >= 16) ? 1 : 1 : 1; if (level == CompPlanLib.Globals.performance_target_level.Employee && current_date.Day >= 1) { current_date = current_date.AddMonths(1); } if (level == CompPlanLib.Globals.performance_target_level.Store || level == CompPlanLib.Globals.performance_target_level.Channel) { if (current_date.Month != 12) { current_date = current_date.AddMonths(1); } } DateTime pp_start_date = new DateTime(current_date.Year, current_date.Month, start_day, 0, 0, 0); int for_sc = (level == CompPlanLib.Globals.performance_target_level.Employee) ? 1 : 0; DataTable dt = new DataTable(); using (SqlConnection con = new SqlConnection(sqlconn_readonly)) using (SqlDataAdapter dat = new SqlDataAdapter(String.Format("select convert(varchar, start_date, 101) + ' - ' + convert(varchar, end_date, 101) as DateRange, start_date from dbo.commissions_pay_periods where start_date<'{0}' and for_consultants={1} order by end_date desc", pp_start_date, for_sc), con)) dat.Fill(dt); cbPayPeriods.DataSource = dt; cbPayPeriods.DisplayMember = "DateRange"; cbPayPeriods.ValueMember = "start_date"; }
public ProcessingThread(CompPlanLib.CompPlanEngine compplanobj, DateTime run_date, CompPlanLib.Globals.performance_target_level target_level, int rq_id) { compplan = compplanobj; run = run_date; level = target_level; id = rq_id; }
private void cbPayPeriods_SelectionChangeCommitted(object sender, EventArgs e) { if (cbReportLevel.SelectedValue != null) { CompPlanLib.Globals.performance_target_level level = (CompPlanLib.Globals.performance_target_level)cbReportLevel.SelectedValue; LoadEmployees(level); } }
private void LoadAllFormData() { LoadReportLevels(); if (cbReportLevel.SelectedValue != null) { CompPlanLib.Globals.performance_target_level level = (CompPlanLib.Globals.performance_target_level)cbReportLevel.SelectedValue; LoadPayPeriods(level); LoadEmployees(level); } }
private void RunCompPlan() { if (!FormOK()) { return; } try { calcs_running = false; pnlPayPeriods.Enabled = false; pnlReportLevel.Enabled = false; pnlEmployee.Enabled = false; sbLabel.Text = "Running calculations... please wait..."; pnlControls.Visible = false; pbAnimate.Enabled = true; pbAnimate.Visible = true; DateTime run = (DateTime)cbPayPeriods.SelectedValue; CompPlanLib.Globals.performance_target_level level = (CompPlanLib.Globals.performance_target_level)cbReportLevel.SelectedValue; int rq_id = (int)cbEmployee.SelectedValue; ProcessingThread pt = new ProcessingThread(compplan, run, level, rq_id); Thread th = new Thread(pt.DoCalcs); Cursor.Current = Cursors.WaitCursor; th.Start(); while (th.IsAlive) { calcs_running = true; Application.DoEvents(); } calcs_running = th.IsAlive; SetDefaults(); this.WindowState = FormWindowState.Minimized; this.Show(); this.WindowState = FormWindowState.Normal; MessageBox.Show("Run Complete!", "All Done", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception err) { string innermsg = err.InnerException != null ? ", inner exception: " + err.InnerException.Message : ""; MessageBox.Show(String.Format("An unexpected error occured during recalculation: {0}{1}", err.Message, innermsg), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void LoadEmployees(CompPlanLib.Globals.performance_target_level level) { // channel is level 7 in the enum, but user level ID for channel is actually 1 int employee_level = (level == CompPlanLib.Globals.performance_target_level.Channel) ? 1 : (int)level; // for reps, we include anyone in these commissions group(s) since there are now selling store managers who are level 3 [store] but have to paid as a rep string filter = (level == CompPlanLib.Globals.performance_target_level.Employee) ? "commission_group_id in (3,7,10,11,12,13, 29, 30, 32, 37, 38)" : String.Format("user_location_level={0} and isnull(commission_group_id,0) not in (3,7,10,11,12,13,29,30, 32, 37, 38)", employee_level); DateTime ppd_start = (DateTime)cbPayPeriods.SelectedValue; DataTable dt = new DataTable(); using (SqlConnection con = new SqlConnection(sqlconn_readonly)) using (SqlDataAdapter dat = new SqlDataAdapter(String.Format("select distinct rq_id, display_name from dbo.users with(nolock) where rq_id is not null and display_name is not null and {0} and start_date<='{1}' order by display_name", filter, ppd_start.AddDays(3)), con)) dat.Fill(dt); cbEmployee.DataSource = dt; cbEmployee.DisplayMember = "display_name"; cbEmployee.ValueMember = "rq_id"; }