public static DataTable GetNowMachineValueDASAll(string vName, string gname, string pid, string ValueStyle) { DataTable dt = null; DataTable dt_R = MachineValueModel.GetNowMachineValue(vName, gname, pid, "R"); DataTable dt_L = MachineValueModel.GetNowMachineValue(vName, gname, pid, "L"); if (dt_R != null && dt_L != null) { dt_R.Merge(dt_L, true); dt = dt_R; DataView dv = new DataView(dt); dv.Sort = "gName ASC,toolID ASC"; dt = dv.ToTable(); return(dt); } else { return(null); } }
public static byte[] GetNowMachineValueFile(string vName, string gname, string pid, string ValueStyle) { DataTable dt = null; if (vName == "DAS" && ValueStyle == string.Empty && pid == string.Empty) { DataTable dt_R = MachineValueModel.GetNowMachineValue(vName, gname, pid, "R"); DataTable dt_L = MachineValueModel.GetNowMachineValue(vName, gname, pid, "L"); if (dt_R != null || dt_L != null) { if (dt_R != null && dt_L != null) { dt_R.Merge(dt_L, true); dt = dt_R; } else if (dt_R != null && dt_L == null) { dt = dt_R; } else if (dt_R == null && dt_L != null) { dt = dt_L; } DataView dv = new DataView(dt); dv.Sort = "gName ASC,toolID ASC"; dt = dv.ToTable(); if (dt != null && dt.Rows.Count > 0) { dt.Columns.Remove("location_side"); } } } else { dt = MachineValueModel.GetNowMachineValue(vName, gname, pid, ValueStyle); if (dt != null && dt.Rows.Count > 0) { dt.Columns.Remove("location_side"); } } ExcelPackage ep = new ExcelPackage(); if (dt != null && dt.Rows.Count > 0) { //DataSet ds = null; string[,] ds_array = new string[3, 2]; if (vName == "DAS" && pid == string.Empty) { if (gname == string.Empty) { //ds = DBConnector.executeQuery("Intouch", "SELECT 'EPI*MCE*' gname, 'DAS_STY' eqType UNION SELECT 'EPI*MCE*' gname, 'DAS_ESC' eqType UNION SELECT 'ETCH*ME*' gname, '' eqType"); ds_array[0, 0] = "EPI*MCE*"; ds_array[0, 1] = "DAS_STY"; ds_array[1, 0] = "EPI*MCE*"; ds_array[1, 1] = "DAS_ESC"; ds_array[2, 0] = "ETCH*ME*"; ds_array[2, 1] = string.Empty; } if (gname == "EPI*MCE*") { //ds = DBConnector.executeQuery("Intouch", "SELECT 'EPI*MCE*' gname, 'DAS_STY' eqType UNION SELECT 'EPI*MCE*' gname, 'DAS_ESC' eqType "); ds_array[0, 0] = "EPI*MCE*"; ds_array[0, 1] = "DAS_STY"; ds_array[1, 0] = "EPI*MCE*"; ds_array[1, 1] = "DAS_ESC"; ds_array[2, 0] = string.Empty; ds_array[2, 1] = string.Empty; } if (gname == "ETCH*ME*") { //ds = DBConnector.executeQuery("Intouch", "SELECT 'ETCH*ME*' gname, '' eqType"); ds_array[0, 0] = string.Empty; ds_array[0, 1] = string.Empty; ds_array[1, 0] = string.Empty; ds_array[1, 1] = string.Empty; ds_array[2, 0] = "ETCH*ME*"; ds_array[2, 1] = string.Empty; } } else { //ds = DBConnector.executeQuery("Intouch", "SELECT '" + gname + "' gname"); ds_array[0, 0] = string.Empty; ds_array[0, 1] = string.Empty; ds_array[1, 0] = string.Empty; ds_array[1, 1] = string.Empty; ds_array[2, 0] = "ETCH*ME*"; ds_array[2, 1] = string.Empty; } //else if ( gname == string.Empty) //{ // ds = DBConnector.executeQuery("Intouch", "SELECT DISTINCT gname FROM vw_eq_status WHERE vName = '" + vName + "' AND gname IS NOT NULL"); //} //else //{ // ds = DBConnector.executeQuery("Intouch", "SELECT DISTINCT gname FROM vw_eq_status WHERE vName = '" + vName + "' AND gname ='" + gname + "'"); //} DataView dv = new DataView(dt); for (int i = 0; i <= 3 - 1; i++) { if (vName == "DAS" && pid == string.Empty) { if (ds_array[i, 0].ToString() == "EPI*MCE*") { dv.RowFilter = "gname='" + ds_array[i, 0].ToString() + "' and typeName like '" + ds_array[i, 1].ToString() + "%'"; } else if (ds_array[i, 0].ToString() == "ETCH*ME*") { dv.RowFilter = "gname='" + ds_array[i, 0].ToString() + "'"; } dt = dv.ToTable(); } for (int col = dt.Columns.Count - 1; col >= 0; col--) { bool removeColumn = true; foreach (DataRow row in dt.Rows) { if (!row.IsNull(col)) { removeColumn = false; break; } } if (removeColumn && col > 5) { dt.Columns.RemoveAt(col); } } if (dt.Rows.Count > 0 && ds_array[i, 0].ToString() != string.Empty) { ExcelWorksheet sheet1 = null; if (vName == "DAS" && pid == string.Empty) { if (ds_array[i, 0].ToString() == "EPI*MCE*") { ep.Workbook.Worksheets.Add(ds_array[i, 0].ToString().Replace("*", "-") + " " + ds_array[i, 1].ToString()); sheet1 = ep.Workbook.Worksheets[ds_array[i, 0].ToString().Replace("*", "-") + " " + ds_array[i, 1].ToString()]; } else if (ds_array[i, 0].ToString() == "ETCH*ME*") { ep.Workbook.Worksheets.Add(ds_array[i, 0].ToString().Replace("*", "-")); sheet1 = ep.Workbook.Worksheets[ds_array[i, 0].ToString().Replace("*", "-")]; } } else { ep.Workbook.Worksheets.Add("MySheet"); sheet1 = ep.Workbook.Worksheets["MySheet"]; } sheet1.Cells["A1"].LoadFromDataTable(dt, true); sheet1.Cells["A1"].Value = "Toolid"; sheet1.Cells["B1"].Value = "課別"; sheet1.Cells["C1"].Value = "Locationid"; sheet1.Cells["D1"].Value = "柱位"; sheet1.Cells["E1"].Value = "設備類型"; sheet1.Cells["F1"].Value = "廠商"; sheet1.Cells.AutoFitColumns(); } } } else { ep.Workbook.Worksheets.Add("MySheet"); } return(ep.GetAsByteArray()); }