/// <summary> /// Loads cycle data into cycleData Table /// </summary> /// <param name="theData"></param> public void LoadPlanningCycleData(DataTable theData) { if (planningCycleData == null) { planningCycleData = new List <PlanningCycleData>(); } var cycleDBData = theData.GetDataFromDataTable <Cycle>(); var workPlaceList = cycleDBData.GroupBy(test => test.Workplaceid).Select(a => a) .ToList(); foreach (var wp in workPlaceList) { var wpData = cycleDBData.Where(a => a.Workplaceid == wp.Key).ToList(); var currentWorkplace = cycleDBData.Where(a => a.Workplaceid == wp.Key).FirstOrDefault(); PlanningCycleData cycleData = new PlanningCycleData(); cycleData.WorkplaceID = wp.Key; cycleData.TotalShifts = currentWorkplace.TotalShifts; // needed to add this to accommodate for a first shift that is a off day foreach (var DailyCycleCallVal in wpData) { if (DailyCycleCallVal.SQMCycle != 0) { cycleData.DailyCycleCall = DailyCycleCallVal.SQMCycle; break; } } cycleData.CycleCall = currentWorkplace.SQM; cycleData.FaceLength = currentWorkplace.FL; cycleData.MonthCall = currentWorkplace.MonthlyTotalSQM; cycleData.planningCycleDailyData = new System.ComponentModel.BindingList <PlanningCycleDailyData>(); PlanningCycleDailyData dateRow = new PlanningCycleDailyData(); dateRow.RowName = "Date"; dateRow.WorkplaceID = wp.Key; int rowCount = 1; foreach (var d in wpData) { dateRow.setValue(rowCount, d.CalendarDate.ToString("d/M")); rowCount++; } cycleData.planningCycleDailyData.Add(dateRow); PlanningCycleDailyData dateLongRow = new PlanningCycleDailyData(); dateLongRow.RowName = "DateLong"; dateLongRow.WorkplaceID = wp.Key; rowCount = 1; foreach (var d in wpData) { dateLongRow.setValue(rowCount, d.CalendarDate.ToString()); rowCount++; } cycleData.planningCycleDailyData.Add(dateLongRow); PlanningCycleDailyData shiftRow = new PlanningCycleDailyData(); shiftRow.RowName = "Shift"; shiftRow.WorkplaceID = wp.Key; rowCount = 1; foreach (var d in wpData) { shiftRow.setValue(rowCount, d.ShiftDay.ToString()); rowCount++; } cycleData.TotalDays = rowCount; cycleData.planningCycleDailyData.Add(shiftRow); PlanningCycleDailyData AdvBlastRow = new PlanningCycleDailyData(); AdvBlastRow.RowName = "AdvBlast"; AdvBlastRow.WorkplaceID = wp.Key; rowCount = 1; foreach (var d in wpData) { AdvBlastRow.setValue(rowCount, d.AdvBlast.ToString()); rowCount++; } cycleData.TotalDays = rowCount; cycleData.planningCycleDailyData.Add(AdvBlastRow); PlanningCycleDailyData WorkingDaysRow = new PlanningCycleDailyData(); WorkingDaysRow.RowName = "WorkingDays"; WorkingDaysRow.WorkplaceID = wp.Key; rowCount = 1; foreach (var d in wpData) { if (d.Workingday != null) { WorkingDaysRow.setValue(rowCount, d.Workingday.ToString()); } rowCount++; } cycleData.TotalDays = rowCount; cycleData.planningCycleDailyData.Add(WorkingDaysRow); PlanningCycleDailyData defaultCode = new PlanningCycleDailyData(); defaultCode.RowName = "Default Code"; defaultCode.WorkplaceID = wp.Key; rowCount = 1; foreach (var d in wpData) { defaultCode.setValue(rowCount, d.DefaultValue); rowCount++; } cycleData.planningCycleDailyData.Add(defaultCode); PlanningCycleDailyData defaultValue = new PlanningCycleDailyData(); defaultValue.RowName = "Default Value"; defaultValue.WorkplaceID = wp.Key; rowCount = 1; foreach (var d in wpData) { defaultValue.setValue(rowCount, d.DailyDefaultBlastValue.ToString()); rowCount++; } cycleData.planningCycleDailyData.Add(defaultValue); PlanningCycleDailyData moCycleCode = new PlanningCycleDailyData(); moCycleCode.RowName = "Planned Code"; moCycleCode.WorkplaceID = wp.Key; rowCount = 1; foreach (var d in wpData) { moCycleCode.setValue(rowCount, d.MOCycle); rowCount++; } cycleData.planningCycleDailyData.Add(moCycleCode); PlanningCycleDailyData moCyclePlan = new PlanningCycleDailyData(); moCyclePlan.RowName = "Planned Value"; moCyclePlan.WorkplaceID = wp.Key; rowCount = 1; foreach (var d in wpData) { moCyclePlan.setValue(rowCount, d.SQMCycle.ToString()); rowCount++; } cycleData.planningCycleDailyData.Add(moCyclePlan); planningCycleData.Add(cycleData); } }
private void viewPlanningStoping_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { try { string WorkplaceID = viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["Workplaceid"]).ToString(); string SectionID = viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["SectionID"]).ToString(); var WPPlanningData = PlanningClass.PlanningCycle.planningCycleData .Where(a => a.WorkplaceID == WorkplaceID) .FirstOrDefault(); if (e.Column.FieldName == "MonthlyReefSQM") { int WasteSQM = Convert.ToInt32(viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyWatseSQM"])); int newCall = Convert.ToInt32(viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyReefSQM"])) + WasteSQM; viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyTotalSQM"], newCall); WPPlanningData.MonthCall = newCall; ucCycleScreen1.RefreshGrid(); } if (e.Column.FieldName == "MonthlyWatseSQM") { int ReefSQM = Convert.ToInt32(viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyReefSQM"])); int newCall = Convert.ToInt32(viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyWatseSQM"])) + ReefSQM; viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyTotalSQM"], newCall); WPPlanningData.MonthCall = newCall; ucCycleScreen1.RefreshGrid(); } if (e.Column.FieldName == "MonthlyTotalSQM") { string theCallValue = viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"]).ToString(); if (Convert.ToDouble(theCallValue) == 0) { if (WPPlanningData != null) { double newCall = WPPlanningData.DailyCycleCall * WPPlanningData.TotalShifts; viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"], newCall.ToString()); } } else { viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"], e.Value.ToString()); } //if (viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"]).ToString() != TotlSqmLbl.Text) //{ // viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"], e.Value.ToString()); //} //viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"], e.Value.ToString()); } // when Face Length changes we need to update the cycle face length value if (e.Column.FieldName == "FL") { double newFL = Convert.ToDouble(e.Value.ToString()); if (WPPlanningData != null) { WPPlanningData.FaceLength = newFL; double newCall = WPPlanningData.DailyCycleCall * WPPlanningData.TotalShifts; WPPlanningData.CycleCall = newCall; viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"], newCall); var updateCycle = PlanningClass.PlanningCycle.planningCycleData .Where(a => a.WorkplaceID == WorkplaceID) .FirstOrDefault(); if (updateCycle != null) { PlanningClass.PlanningCycle.planningCycleData.Remove(updateCycle); updateCycle = null; PlanningClass.AddCyclePlan(WorkplaceID, SectionID, PlanningClass.PlanningSettings.MOSectionID, PlanningClass.PlanningSettings.ProdMonth, PlanningClass.PlanningSettings.ActivityID, WPPlanningData.FaceLength); } WPPlanningData = null; var wpCycleDataNew = PlanningClass.PlanningCycle.planningCycleData .Where(a => a.WorkplaceID == WorkplaceID) .FirstOrDefault(); newCall = wpCycleDataNew.DailyCycleCall * wpCycleDataNew.TotalShifts; int MonthlyTotalSQM = Convert.ToInt32(viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyTotalSQM"])); wpCycleDataNew.CycleCall = newCall; wpCycleDataNew.MonthCall = MonthlyTotalSQM; wpCycleDataNew.UpdateCycleData(); viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"], wpCycleDataNew.CycleCall.ToString()); ucCycleScreen1.CycleData = wpCycleDataNew; ucCycleScreen1.SetData(); ucCycleScreen1.RefreshGrid(); } else { PlanningCycleData newCycleData = new PlanningCycleData(); newCycleData.WorkplaceID = WorkplaceID; newCycleData.FaceLength = newFL; PlanningClass.PlanningCycle.planningCycleData.Add(newCycleData); PlanningClass.AddCyclePlan(WorkplaceID, SectionID, PlanningClass.PlanningSettings.MOSectionID, PlanningClass.PlanningSettings.ProdMonth, PlanningClass.PlanningSettings.ActivityID, newFL); var wpCycleDataNew = PlanningClass.PlanningCycle.planningCycleData .Where(a => a.WorkplaceID == WorkplaceID) .FirstOrDefault(); double newCall = wpCycleDataNew.DailyCycleCall * wpCycleDataNew.TotalShifts; int MonthlyTotalSQM = Convert.ToInt32(viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyTotalSQM"])); wpCycleDataNew.CycleCall = newCall; wpCycleDataNew.MonthCall = MonthlyTotalSQM; wpCycleDataNew.UpdateCycleData(); viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"], wpCycleDataNew.CycleCall.ToString()); ucCycleScreen1.CycleData = wpCycleDataNew; ucCycleScreen1.SetData(); ucCycleScreen1.RefreshGrid(); } } if (e.Column.FieldName == "callValue") { decimal TotMonthcall = Convert.ToInt32(viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyTotalSQM"])); decimal ReefMonthcall = Convert.ToInt32(viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["MonthlyReefSQM"])); decimal ratio = 0; if (ReefMonthcall != 0) { ratio = TotMonthcall / ReefMonthcall; } int TotActCall = Convert.ToInt32(viewPlanningStoping.GetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["callValue"])); int ReefCall = 0; int WasteCall = 0; if (ratio != 0) { ReefCall = Convert.ToInt32(Convert.ToDecimal(TotActCall) / ratio); } if (TotMonthcall != 0) { WasteCall = TotActCall - ReefCall; } else { ReefCall = TotActCall; } viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["ReefSQM"], ReefCall); viewPlanningStoping.SetRowCellValue(e.RowHandle, viewPlanningStoping.Columns["WasteSQM"], WasteCall); //viewPlanningDevelopment.SetRowCellValue(e.RowHandle, viewPlanningDevelopment.Columns["Metresadvance"], e.Value.ToString()); } MWDataManager.clsDataAccess _CalcData = new MWDataManager.clsDataAccess() { ConnectionString = TConnections.GetConnectionString(PlanningClass.systemDBTag, PlanningClass.UserCurrentInfo.Connection), queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement, queryReturnType = MWDataManager.ReturnType.DataTable }; BandedGridView view; view = sender as BandedGridView; object row = view.GetRow(view.FocusedRowHandle); // get the current row (row as DataRowView)["hasChanged"] = 1; if (view.FocusedColumn.FieldName == "SectionID") { // updates start and en date based on selected miner. Will update if no date or date is different from current string selectedSectioID = (row as DataRowView)["SectionID"].ToString(); DataRow[] result = PlanningClass.tblSectionStartEndDates.Select(String.Format("SectionID = '{0}'", selectedSectioID)); if (result.Length == 1) { if ((row as DataRowView)["StartDate"] == null || (row as DataRowView)["StartDate"] != result[0]["StartDate"].ToString()) { (row as DataRowView)["StartDate"] = result[0]["StartDate"].ToString(); } if ((row as DataRowView)["EndDate"] == null || (row as DataRowView)["EndDate"] != result[0]["EndDate"].ToString()) { (row as DataRowView)["EndDate"] = result[0]["EndDate"].ToString(); } } } if (PlanningClass.PlanningSettings.ActivityID == 0) { if (view.FocusedColumn.FieldName == "ReefSQM" || view.FocusedColumn.FieldName == "WasteSQM" || view.FocusedColumn.FieldName == "FL" || view.FocusedColumn.FieldName == "SW" || view.FocusedColumn.FieldName == "CW" || view.FocusedColumn.FieldName == "CMGT" || view.FocusedColumn.FieldName == "FaceCMGT" || view.FocusedColumn.FieldName == "CubicsReef" || view.FocusedColumn.FieldName == "CubicsWaste") { if ((row as DataRowView)["FaceCMGT"] == null || (row as DataRowView)["FaceCMGT"].ToString() == "") { (row as DataRowView)["FaceCMGT"] = 0; } if ((row as DataRowView)["CW"] == null || (row as DataRowView)["CW"].ToString() == "") { (row as DataRowView)["CW"] = 0; } if ((row as DataRowView)["CubicsReef"] == null || (row as DataRowView)["CubicsReef"].ToString() == "") { (row as DataRowView)["CubicsReef"] = 0; } if ((row as DataRowView)["CubicsWaste"] == null || (row as DataRowView)["CubicsWaste"].ToString() == "") { (row as DataRowView)["CubicsWaste"] = 0; } if ((row as DataRowView)["DynamicCubicGT"] == null || (row as DataRowView)["DynamicCubicGT"].ToString() == "") { (row as DataRowView)["DynamicCubicGT"] = 0; } string cubicgrams = (row as DataRowView)["DynamicCubicGT"].ToString(); _CalcData.SqlStatement = "DECLARE @StopeWidth float,@CubicMeters float,@FaceLength float,@OnReefSQM float, @OffReefSQM float, " + "@CMGT float,@CMKGT float,@Workplaceid varchar(50),@FaceCMGT float,@FaceAdvance float,@GoldBrokenSQM float,@UraniumBrokenSQM float, " + "@GoldBrokenCUB float,@UraniumBrokenCUB float, @FaceBrokenKG float, @FaceTonsSQM float, @FaceTonsCube float, @FaceValue float, " + "@TrammedTons float, @TrammedValue float,@ChannelW int,@cubicgrams float " + " SET @StopeWidth = " + (row as DataRowView)["SW"].ToString() + " SET @CubicMeters = " + (row as DataRowView)["CubicMetres"] + " SET @FaceLength = " + (row as DataRowView)["FL"] + " SET @OnReefSQM = " + (row as DataRowView)["ReefSQM"] + " SET @OffReefSQM = " + (row as DataRowView)["WasteSQM"] + " SET @CMGT = " + (row as DataRowView)["CMGT"] + " SET @CMKGT = " + (row as DataRowView)["CMKGT"] + " SET @Workplaceid = '" + (row as DataRowView)["Workplaceid"] + "' " + " SET @FaceCMGT = " + (row as DataRowView)["FaceCMGT"] + " SET @ChannelW = " + (row as DataRowView)["CW"] + "SET @cubicgrams=" + (row as DataRowView)["DynamicCubicGT"] + "" + " SET @FaceAdvance = dbo.CalcFaceAdvance(@StopeWidth,@CubicMeters,@FaceLength,@OnReefSQM,@OffReefSQM) " + " set @GoldBrokenSQM = dbo.CalcGoldBrokenSQM(@OnReefSQM,@CMGT,@Workplaceid) " + " set @GoldBrokenCUB = dbo.CalcGoldBrokenCUB(@CubicMeters,@cubicgrams,@StopeWidth,@Workplaceid) " + " set @UraniumBrokenSQM = dbo.CalcGoldBrokenSQM(@OnReefSQM,@CMKGT,@Workplaceid) " + "set @UraniumBrokenCUB=dbo.CalcUraniumBrokenCUB(@CubicMeters,@cubicgrams,@StopeWidth,@Workplaceid) " + " set @FaceBrokenKG = dbo.CalcFaceBrokenKG(@OnReefSQM,@FaceCMGT,@Workplaceid) " + " set @FaceTonsSQM = dbo.CalcFaceTonsSQM(@OnReefSQM + @OffReefSQM,@StopeWidth,@Workplaceid)" + " SET @FaceTonsCube = dbo.CalcFaceTonsCUBE(@CubicMeters,@Workplaceid) " + " SET @FaceValue = dbo.CalcFaceValue(@GoldBrokenSQM + @GoldBrokenCUB,@FaceTonsSQM + @FaceTonsCube) " + " SET @TrammedTons = dbo.CalcTrammedTons(@FaceTonsSQM + @FaceTonsCube) " + " SET @TrammedValue = dbo.CalcTrammedValue(@TrammedTons,@GoldBrokenSQM + @GoldBrokenCUB) " + " SELECT @FaceAdvance FaceAdvance,@GoldBrokenSQM GoldBrokenSQM,@UraniumBrokenSQM UraniumBrokenSQM, @GoldBrokenCUB GoldBrokenCUB,@UraniumBrokenCUB UraniumBrokenCUB,@FaceBrokenKG FaceBrokenKG, " + " @FaceTonsSQM FaceTonsSQM,@FaceTonsCube FaceTonsCubes,@FaceValue FaceValue,@TrammedTons TrammedTons, @TrammedValue TrammedValue,dbo.CalcIdealSW(@ChannelW) IdealSW "; _CalcData.ExecuteInstruction(); foreach (DataRow r in _CalcData.ResultsDataTable.Rows) { (row as DataRowView)["FaceAdvance"] = r["FaceAdvance"]; (row as DataRowView)["GoldBroken"] = Convert.ToDecimal(r["GoldBrokenSQM"]) + (Convert.ToDecimal(r["GoldBrokenCUB"]) / 1000); (row as DataRowView)["UraniumBroken"] = Convert.ToDecimal(r["UraniumBrokenSQM"]) + (Convert.ToDecimal(r["UraniumBrokenCUB"]) / 100); (row as DataRowView)["FaceBrokenKG"] = r["FaceBrokenKG"]; (row as DataRowView)["FaceTons"] = Convert.ToDecimal(r["FaceTonsSQM"]) + Convert.ToDecimal(r["FaceTonsCubes"]); (row as DataRowView)["FaceValue"] = r["FaceValue"]; (row as DataRowView)["TrammedTons"] = r["TrammedTons"]; (row as DataRowView)["TrammedValue"] = r["TrammedValue"]; (row as DataRowView)["IdealSW"] = r["IdealSW"]; (row as DataRowView)["CubicMetres"] = Convert.ToDecimal((row as DataRowView)["CubicsReef"]) + Convert.ToDecimal((row as DataRowView)["CubicsWaste"]); } string theSQM = String.Format("{0:0}", (row as DataRowView)["ReefSQM"]); string theWasteSQM = String.Format("{0:0}", (row as DataRowView)["WasteSQM"]); Int32 theTotal = Convert.ToInt32(theSQM) + Convert.ToInt32(theWasteSQM); // (row as DataRowView)["callValue"] = theTotal; //editTotalPlanSQM.Text = Convert.ToString(getTotalSQM(tblPrePlanData)); viewPlanningStoping.UpdateTotalSummary(); calVariance(); } } viewPlanningStoping.RefreshData(); } catch (Exception eException) { var error = eException.Message; } }