private void loadMacData() { DataTable dt = dalMac.Select(); DataTable dt_Mac = NewMacTable(); DataRow row_Mac; DataTable dt_Plan = dalPlanning.Select(); foreach (DataRow row in dt.Rows) { row_Mac = dt_Mac.NewRow(); row_Mac[headerID] = row[dalMac.MacID]; row_Mac[headerName] = row[dalMac.MacName]; row_Mac[headerTon] = row[dalMac.MacTon]; row_Mac[headerLocation] = row[dalMac.MacLocation]; string runningItem = "", nextItem = ""; DateTime runningEnd = new DateTime(), nextStart = new DateTime(), nextEnd = new DateTime(); dt_Plan.AcceptChanges(); foreach (DataRow plan in dt_Plan.Rows) { if (row[dalMac.MacID].Equals(plan[dalPlanning.machineID])) { if (plan[dalPlanning.planStatus].Equals(text.planning_status_running)) { runningItem = "(" + plan[dalPlanning.partCode].ToString() + ") " + plan[dalItem.ItemName].ToString(); runningEnd = Convert.ToDateTime(plan[dalPlanning.productionEndDate]); } else if (plan[dalPlanning.planStatus].Equals(text.planning_status_pending)) { if (nextStart != default(DateTime)) { DateTime temp = Convert.ToDateTime(plan[dalPlanning.productionStartDate]); if (temp < nextStart) { nextItem = "(" + plan[dalPlanning.partCode].ToString() + ") " + plan[dalItem.ItemName].ToString(); nextStart = Convert.ToDateTime(plan[dalPlanning.productionStartDate]); nextEnd = Convert.ToDateTime(plan[dalPlanning.productionEndDate]); } } else { nextItem = "(" + plan[dalPlanning.partCode].ToString() + ") " + plan[dalItem.ItemName].ToString(); nextStart = Convert.ToDateTime(plan[dalPlanning.productionStartDate]); nextEnd = Convert.ToDateTime(plan[dalPlanning.productionEndDate]); } } plan.Delete(); } } dt_Plan.AcceptChanges(); row_Mac[headerRunning] = runningItem; row_Mac[headerRunning] = runningItem; row_Mac[headerEstimateEnd] = runningEnd; row_Mac[headerNext] = nextItem; row_Mac[headerNextStart] = nextStart; row_Mac[headerNextEnd] = nextEnd; dt_Mac.Rows.Add(row_Mac); } dgvMac.DataSource = null; if (dt_Mac.Rows.Count > 0) { dgvMac.DataSource = dt_Mac; dgvMacUIEdit(dgvMac); dgvMac.ClearSelection(); } }
private void LoadProductionRecord() { recordLoaded = false; dgvMoreDetail.DataSource = null; DataTable dt = NewProductionRecordTable(); dt_ProRecord = dalProRecord.SelectWithItemInfo(); DataTable dt_Mac = dalMac.Select(); int index = 1; foreach (DataRow row in dt_ProRecord.Rows) { int macID = int.TryParse(row[dalPlan.machineID].ToString(), out macID) ? macID : 0; string fac = tool.getFactoryNameFromMachineID(macID.ToString(), dt_Mac); DateTime proDate = Convert.ToDateTime(row[dalProRecord.ProDate]).Date; int planID = int.TryParse(row[dalPlan.planID].ToString(), out planID) ? planID : 0; int sheetID = int.TryParse(row[dalProRecord.SheetID].ToString(), out sheetID) ? sheetID : 0; string shift = row[dalProRecord.Shift].ToString(); string itemCode = row[dalItem.ItemCode].ToString(); string itemName = row[dalItem.ItemName].ToString(); int totalStockIn = int.TryParse(row[dalProRecord.TotalProduced].ToString(), out totalStockIn) ? totalStockIn : 0; string rawMat = row[dalItem.ItemMaterial].ToString(); string colorMat = row[dalItem.ItemMBatch].ToString(); bool dataMatched = true; #region filter date DateTime dateFrom = dtpFrom.Value.Date; DateTime dateTo = dtpTo.Value.Date; if (proDate < dateFrom || proDate > dateTo) { dataMatched = false; } #endregion #region filter item string filterName = cmbPartName.Text; string filterCode = cmbPartCode.Text; if (!string.IsNullOrEmpty(filterName) && filterName != itemName) { dataMatched = false; } if (!string.IsNullOrEmpty(filterCode) && filterCode != itemCode) { dataMatched = false; } #endregion #region filter factory string filterFac = cmbFac.Text; if (filterFac != "All" && !string.IsNullOrEmpty(filterFac) && filterFac != fac) { dataMatched = false; } #endregion #region filter machine string filterMac = cmbMac.Text; if (!string.IsNullOrEmpty(filterMac) && filterMac != macID.ToString()) { dataMatched = false; } #endregion if (dataMatched) { DataRow dt_Row = dt.NewRow(); dt_Row[header_Index] = index; dt_Row[header_Fac] = fac; dt_Row[header_Mac] = macID; if (cbShowOnlyOneRowForEachPlan.Checked) { dt_Row[header_ProDateTo] = proDate; dt_Row[header_ProDateFrom] = proDate; } else { dt_Row[header_ProDate] = proDate; dt_Row[header_SheetID] = sheetID; dt_Row[header_Shift] = shift; } dt_Row[header_PlanID] = planID; dt_Row[header_PartName] = itemName; dt_Row[header_StockIn] = totalStockIn; if (cbShowRawMat.Checked) { dt_Row[header_RawMat] = rawMat; } if (cbShowColorMat.Checked) { dt_Row[header_ColorMat] = colorMat; } dt.Rows.Add(dt_Row); index++; } } #region show only 1 row for each plan if (cbShowOnlyOneRowForEachPlan.Checked) { DataTable dt_FilterDuplicatePlan = NewProductionRecordTable(); string previousPlanID = null; int totalStockIn = 0; //sorting dt by planID and date dt.DefaultView.Sort = header_PlanID + " ASC"; dt = dt.DefaultView.ToTable(); foreach (DataRow row in dt.Rows) { DateTime proDate = Convert.ToDateTime(row[header_ProDateTo]); if (previousPlanID == row[header_PlanID].ToString()) { totalStockIn += Convert.ToInt32(row[header_StockIn].ToString()); dt_FilterDuplicatePlan.Rows[dt_FilterDuplicatePlan.Rows.Count - 1][header_ProDateFrom] = proDate; dt_FilterDuplicatePlan.Rows[dt_FilterDuplicatePlan.Rows.Count - 1][header_StockIn] = totalStockIn; } else { previousPlanID = row[header_PlanID].ToString(); totalStockIn = Convert.ToInt32(row[header_StockIn].ToString()); dt_FilterDuplicatePlan.ImportRow(row); } //if(previousPlanID == null) //{ // previousPlanID = row[header_PlanID].ToString(); // totalStockIn = Convert.ToInt32(row[header_StockIn].ToString()); // dt_FilterDuplicatePlan.Rows.Add(row); //} //else if(previousPlanID == row[header_PlanID].ToString()) //{ // totalStockIn += Convert.ToInt32(row[header_StockIn].ToString()); // dt_FilterDuplicatePlan.Rows[dt_FilterDuplicatePlan.Rows.Count - 1][header_StockIn] = totalStockIn; //} //else //{ // previousPlanID = row[header_PlanID].ToString(); // totalStockIn = Convert.ToInt32(row[header_StockIn].ToString()); // dt_FilterDuplicatePlan.Rows.Add(row); //} } dt_FilterDuplicatePlan.DefaultView.Sort = header_Mac + " ASC, " + header_ProDateFrom + " ASC"; dt_FilterDuplicatePlan = dt_FilterDuplicatePlan.DefaultView.ToTable(); int indexNo = 1; foreach (DataRow row in dt_FilterDuplicatePlan.Rows) { row[header_Index] = indexNo; indexNo++; } dt = dt_FilterDuplicatePlan.Copy(); } #endregion dgvProductionRecord.DataSource = dt; dgvProductionRecord.ClearSelection(); recordLoaded = true; }