internal static byte[] GetPhoneCallFile(string tool, string phoneCallType) { IEnumerable <PhoneCallModel> al = null; al = PhoneCallModel.GetPhoneCallList(tool, phoneCallType); ExcelPackage ep = new ExcelPackage(); ep.Workbook.Worksheets.Add("MySheet"); ExcelWorksheet sheet1 = ep.Workbook.Worksheets["MySheet"]; sheet1.Cells["A1"].Value = "FullTagName"; sheet1.Cells["B1"].Value = "部門"; sheet1.Cells["C1"].Value = "AlarmID"; sheet1.Cells["D1"].Value = "DataTag"; sheet1.Cells["E1"].Value = "Setting"; sheet1.Cells["F1"].Value = "plc_id"; sheet1.Cells["G1"].Value = "sensorID"; sheet1.Cells["H1"].Value = "最後修改者"; if (al.Count() > 0) { int i = 2; foreach (var item in al) { sheet1.Cells["A" + i].Value = item.FullTagName; //"AlarmId" sheet1.Cells["B" + i].Value = item.department_name; //"時間" sheet1.Cells["C" + i].Value = item.AlarmID; //"Alarm 訊息" sheet1.Cells["D" + i].Value = item.data_Tag; //"ToolID" sheet1.Cells["E" + i].Value = item.CallOut; //"數值" sheet1.Cells["F" + i].Value = item.plc_id; //"Alarm 訊息" sheet1.Cells["G" + i].Value = item.sensorID; //"Alarm 訊息" sheet1.Cells["H" + i].Value = item.login_name; //"Alarm 訊息" i++; } sheet1.Cells.AutoFitColumns(); sheet1.Column(1).Width = 0; sheet1.Column(5).Width = 0; sheet1.Column(6).Width = 0; } return(ep.GetAsByteArray()); }
public static PhoneCallModel GetPhoneCall(string tagname) { PhoneCallModel PhoneCall = new PhoneCallModel(); string sqlStr = "SELECT department_name,FullTagName,data_Tag,plc_id,sensorID,login_name,CallOut,Alarmid FROM vw_PhoneCallSetting where fulltagName = '" + tagname + "'"; DataSet DeptDS = DBConnector.executeQuery("Intouch", sqlStr); PhoneCall = (from dept in DeptDS.Tables[0].AsEnumerable() select new PhoneCallModel { department_name = dept.Field <string>("department_name"), FullTagName = dept.Field <string>("FullTagName"), data_Tag = dept.Field <string>("data_Tag"), CallOut = dept.Field <bool>("CallOut"), plc_id = dept.Field <int>("plc_id"), sensorID = dept.Field <string>("sensorID"), login_name = dept.Field <string>("login_name"), AlarmID = dept.Field <string>("Alarmid") }).FirstOrDefault(); return(PhoneCall); }