|
@@ -12,6 +12,12 @@ using System.Text;
|
12
|
12
|
using System.Threading.Tasks;
|
13
|
13
|
using System.Windows.Forms;
|
14
|
14
|
|
|
15
|
+//Add
|
|
16
|
+using System.Reflection;
|
|
17
|
+using Excel = Microsoft.Office.Interop.Excel;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
15
|
21
|
namespace Jdas_Mbic
|
16
|
22
|
{
|
17
|
23
|
public partial class JdasMbic : Form
|
|
@@ -49,6 +55,7 @@ namespace Jdas_Mbic
|
49
|
55
|
dataGridView_TableSetting.Rows.Add();
|
50
|
56
|
tempstr = string.Format("{0:0.0}", TempDbmData);
|
51
|
57
|
dataGridView_TableSetting[0, i].Value = Convert.ToString(tempstr) + " dBm"; ;
|
|
58
|
+ dataGridView_TableSetting[1, i].Value = "0";
|
52
|
59
|
TempDbmData = TempDbmData + 0.5;
|
53
|
60
|
|
54
|
61
|
}
|
|
@@ -79,6 +86,7 @@ namespace Jdas_Mbic
|
79
|
86
|
tempstr = string.Format("{0:0}", Temp_DL_Data);
|
80
|
87
|
dataGridView_TableSetting[0, i].Value = Convert.ToString(tempstr) + " dBm";
|
81
|
88
|
Temp_DL_Data = Temp_DL_Data - 1;
|
|
89
|
+ dataGridView_TableSetting[1, i].Value = "0";
|
82
|
90
|
|
83
|
91
|
}
|
84
|
92
|
break;
|
|
@@ -90,6 +98,7 @@ namespace Jdas_Mbic
|
90
|
98
|
tempstr = string.Format("{0:0}", Temp_UL_Data);
|
91
|
99
|
dataGridView_TableSetting[0, i].Value = Convert.ToString(tempstr) + " dBm";
|
92
|
100
|
Temp_UL_Data = Temp_UL_Data - 1;
|
|
101
|
+ dataGridView_TableSetting[1, i].Value = "0";
|
93
|
102
|
}
|
94
|
103
|
break;
|
95
|
104
|
}
|
|
@@ -115,6 +124,7 @@ namespace Jdas_Mbic
|
115
|
124
|
tempstr = string.Format("{0:0}", Temp_Data);
|
116
|
125
|
dataGridView_TableSetting[0, i].Value = Convert.ToString(tempstr) + " ℃";
|
117
|
126
|
Temp_Data = Temp_Data - 5;
|
|
127
|
+ dataGridView_TableSetting[1, i].Value = "0";
|
118
|
128
|
|
119
|
129
|
}
|
120
|
130
|
foreach (DataGridViewRow row in this.dataGridView_TableSetting.Rows)
|
|
@@ -502,7 +512,7 @@ namespace Jdas_Mbic
|
502
|
512
|
}
|
503
|
513
|
Int64 Timer_Cnt = 0;
|
504
|
514
|
Int32 ReqTimer_Cnt = 0;
|
505
|
|
-
|
|
515
|
+ Bluecell_BootProtocol bluecell_BootProtocol = new Bluecell_BootProtocol();
|
506
|
516
|
private void timer1_Tick(object sender, EventArgs e)
|
507
|
517
|
{
|
508
|
518
|
Update_Serial update_Serial = null;
|
|
@@ -538,7 +548,7 @@ namespace Jdas_Mbic
|
538
|
548
|
}
|
539
|
549
|
if (ReqTimer_Cnt > 6)
|
540
|
550
|
{
|
541
|
|
- // bluecell_BootProtocol.Bluecell_RF_Status_Req(serial);
|
|
551
|
+ bluecell_BootProtocol.Bluecell_RF_Status_Req(serial);
|
542
|
552
|
ReqTimer_Cnt = 0;
|
543
|
553
|
}
|
544
|
554
|
}
|
|
@@ -825,5 +835,198 @@ namespace Jdas_Mbic
|
825
|
835
|
temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 2] = 1; //CRC
|
826
|
836
|
serial.Serial_DataSend(temp_buf, temp_buf.Length);
|
827
|
837
|
}
|
|
838
|
+
|
|
839
|
+ private void button_ExcelSave_Click(object sender, EventArgs e)
|
|
840
|
+ {
|
|
841
|
+ GridViewExcel(this.dataGridView_TableSetting);
|
|
842
|
+ button_ExcelKill_Click(null, null);
|
|
843
|
+ //ExportExcel(false);
|
|
844
|
+ }
|
|
845
|
+
|
|
846
|
+ public void GridViewExcel(DataGridView grid)
|
|
847
|
+ {
|
|
848
|
+ Excel.Application oXL;
|
|
849
|
+ Excel._Workbook oWB;
|
|
850
|
+ Excel._Worksheet oSheet;
|
|
851
|
+ //Excel.Range oRng;
|
|
852
|
+ object missingType = Type.Missing;
|
|
853
|
+
|
|
854
|
+ this.saveFileDialog1.FileName = Application.StartupPath + "\\" + comboBox_TableName.Text;
|
|
855
|
+ this.saveFileDialog1.DefaultExt = "xls";
|
|
856
|
+ this.saveFileDialog1.Filter = "Excel files (*.xls)|*.xls";
|
|
857
|
+ this.saveFileDialog1.InitialDirectory = "{Desktop}";
|
|
858
|
+ //DialogResult result = saveFileDialog1.ShowDialog();
|
|
859
|
+ //if (result == DialogResult.OK)
|
|
860
|
+ {
|
|
861
|
+ try
|
|
862
|
+ {
|
|
863
|
+ //Start Excel and get Application object.
|
|
864
|
+ oXL = new Excel.Application();
|
|
865
|
+ oXL.Visible = false;
|
|
866
|
+
|
|
867
|
+ //Get a new workbook.
|
|
868
|
+ oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
|
|
869
|
+ //oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
|
|
870
|
+ oSheet = (Excel._Worksheet)oWB.ActiveSheet;
|
|
871
|
+ //oSheet = oWB.Worksheets.get_Item(1) as Excel.Worksheet;
|
|
872
|
+ //oSheet = (Excel.Worksheet)oWB.Worksheets.Item[2] as Excel._Worksheet;
|
|
873
|
+
|
|
874
|
+ //oWB.Worksheets.Item[1] as Excel._Worksheet;
|
|
875
|
+
|
|
876
|
+ //Add table headers going cell by cell.
|
|
877
|
+ int k = 0;
|
|
878
|
+ string[] colHeader = new string[grid.ColumnCount];
|
|
879
|
+ for (int i = 0; i < grid.Columns.Count; i++)
|
|
880
|
+ {
|
|
881
|
+ oSheet.Cells[1, i + 1] = grid.Columns[i].HeaderText;
|
|
882
|
+
|
|
883
|
+ k = i + 65;
|
|
884
|
+ colHeader[i] = Convert.ToString((char)k);
|
|
885
|
+ }
|
|
886
|
+ //Format A1:D1 as bold, vertical alignment = center.
|
|
887
|
+ oSheet.get_Range("A1", colHeader[colHeader.Length - 1] + "1").Font.Bold = true;
|
|
888
|
+ oSheet.get_Range("A1", colHeader[colHeader.Length - 1] + "1").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
|
|
889
|
+
|
|
890
|
+ // Create an array to multiple values at once.
|
|
891
|
+ object[,] saNames = new object[grid.RowCount, grid.ColumnCount];
|
|
892
|
+
|
|
893
|
+ string tp;
|
|
894
|
+ for (int i = 0; i < grid.RowCount; i++)
|
|
895
|
+ {
|
|
896
|
+ for (int j = 0; j < grid.ColumnCount; j++)
|
|
897
|
+ {
|
|
898
|
+ tp = grid.Rows[i].Cells[j].ValueType.Name;
|
|
899
|
+ if (tp == "String") //2000-01-01 형태의 날짜 필터하기 위함(숫자로 변환 방지)
|
|
900
|
+ saNames[i, j] = "'" + grid.Rows[i].Cells[j].Value.ToString();
|
|
901
|
+ else
|
|
902
|
+ saNames[i, j] = grid.Rows[i].Cells[j].Value;
|
|
903
|
+ }
|
|
904
|
+ }
|
|
905
|
+
|
|
906
|
+ //Fill A2:B6 with an array of values (First and Last Names).
|
|
907
|
+ //oSheet.get_Range("A2", "B6").Value2 = saNames;
|
|
908
|
+ oSheet.get_Range(colHeader[0] + "2", colHeader[colHeader.Length - 1] + (grid.RowCount + 1)).Value2 = saNames;
|
|
909
|
+
|
|
910
|
+ oXL.Visible = false;
|
|
911
|
+ oXL.UserControl = false;
|
|
912
|
+ oWB.SaveAs(saveFileDialog1.FileName,
|
|
913
|
+ Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
|
|
914
|
+ missingType, missingType, missingType, missingType,
|
|
915
|
+ Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
|
|
916
|
+ missingType, missingType, missingType, missingType, missingType);
|
|
917
|
+ oWB.Close(false, missingType, missingType);
|
|
918
|
+ Cursor.Current = Cursors.Default;
|
|
919
|
+ MessageBox.Show("Save Success!!!");
|
|
920
|
+ }
|
|
921
|
+ catch (Exception theException)
|
|
922
|
+ {
|
|
923
|
+ String errorMessage;
|
|
924
|
+ errorMessage = "Error: ";
|
|
925
|
+ errorMessage = String.Concat(errorMessage, theException.Message);
|
|
926
|
+ errorMessage = String.Concat(errorMessage, " Line: ");
|
|
927
|
+ errorMessage = String.Concat(errorMessage, theException.Source);
|
|
928
|
+
|
|
929
|
+ MessageBox.Show(errorMessage, "Error");
|
|
930
|
+ }
|
|
931
|
+ }
|
|
932
|
+
|
|
933
|
+ }
|
|
934
|
+
|
|
935
|
+ public void ReadExcelData(string path)
|
|
936
|
+ { // path는 Excel파일의 전체 경로입니다.
|
|
937
|
+ // 예. D:\test\test.xslx
|
|
938
|
+ Excel.Application excelApp = null;
|
|
939
|
+ Excel.Workbook wb = null;
|
|
940
|
+ Excel.Worksheet ws = null;
|
|
941
|
+ try
|
|
942
|
+ {
|
|
943
|
+ excelApp = new Excel.Application();
|
|
944
|
+ wb = excelApp.Workbooks.Open(path);
|
|
945
|
+ // path 대신 문자열도 가능합니다
|
|
946
|
+ // 예. Open(@"D:\test\test.xslx");
|
|
947
|
+ ws = wb.Worksheets.get_Item(1) as Excel.Worksheet;
|
|
948
|
+ // 첫번째 Worksheet를 선택합니다.
|
|
949
|
+ Excel.Range rng = ws.UsedRange; // '여기'
|
|
950
|
+ // 현재 Worksheet에서 사용된 셀 전체를 선택합니다.
|
|
951
|
+ object[,] data = rng.Value;
|
|
952
|
+ // 열들에 들어있는 Data를 배열 (One-based array)로 받아옵니다.
|
|
953
|
+ for (int r = 1; r < data.GetLength(0); r++)
|
|
954
|
+ {
|
|
955
|
+ for (int c = 1; c <= data.GetLength(1); c++)
|
|
956
|
+ {
|
|
957
|
+ if (data[r, c] == null)
|
|
958
|
+ {
|
|
959
|
+ continue;
|
|
960
|
+ }
|
|
961
|
+ //dataGridView_TableSetting.SelectedRows(r - 1).Cells(c - 1).Value = data[r + 1, c];
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+ // Data 빼오기
|
|
965
|
+ // data[r, c] 는 excel의 (r, c) 셀 입니다.
|
|
966
|
+ // data.GetLength(0)은 엑셀에서 사용되는 행의 수를 가져오는 것이고,
|
|
967
|
+ // data.GetLength(1)은 엑셀에서 사용되는 열의 수를 가져오는 것입니다.
|
|
968
|
+ // GetLength와 [ r, c] 의 순서를 바꿔서 사용할 수 있습니다.
|
|
969
|
+ }
|
|
970
|
+ dataGridView_TableSetting.Rows[r - 1].Cells[1].Value = data[r + 1, 2];
|
|
971
|
+ }
|
|
972
|
+ wb.Close(true);
|
|
973
|
+ excelApp.Quit();
|
|
974
|
+ }
|
|
975
|
+ catch (Exception ex)
|
|
976
|
+ {
|
|
977
|
+ throw ex;
|
|
978
|
+ }
|
|
979
|
+ finally
|
|
980
|
+ {
|
|
981
|
+ ReleaseExcelObject(ws);
|
|
982
|
+ ReleaseExcelObject(wb);
|
|
983
|
+ ReleaseExcelObject(excelApp);
|
|
984
|
+ button_ExcelKill_Click(null,null);
|
|
985
|
+ }
|
|
986
|
+ }
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+ private void ReleaseExcelObject(object obj)
|
|
991
|
+ {
|
|
992
|
+ try
|
|
993
|
+ {
|
|
994
|
+ System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
|
|
995
|
+ obj = null;
|
|
996
|
+ }
|
|
997
|
+ catch (Exception ex)
|
|
998
|
+ {
|
|
999
|
+ obj = null;
|
|
1000
|
+ MessageBox.Show("Unable to release the Object " + ex.ToString());
|
|
1001
|
+ }
|
|
1002
|
+ finally
|
|
1003
|
+ {
|
|
1004
|
+ GC.Collect();
|
|
1005
|
+ }
|
|
1006
|
+ }
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+ private void button_ExcelLoad_Click(object sender, EventArgs e)
|
|
1010
|
+ {
|
|
1011
|
+ string path = Application.StartupPath + "\\" + comboBox_TableName.Text + ".xls";
|
|
1012
|
+ ReadExcelData(path);
|
|
1013
|
+ }
|
|
1014
|
+
|
|
1015
|
+ private void button_ExcelKill_Click(object sender, EventArgs e)
|
|
1016
|
+ {
|
|
1017
|
+ System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("EXCEL");
|
|
1018
|
+ foreach (System.Diagnostics.Process p in process)
|
|
1019
|
+ {
|
|
1020
|
+ if (!string.IsNullOrEmpty(p.ProcessName))
|
|
1021
|
+ {
|
|
1022
|
+ try
|
|
1023
|
+ {
|
|
1024
|
+ p.Kill();
|
|
1025
|
+ }
|
|
1026
|
+ catch { }
|
|
1027
|
+ }
|
|
1028
|
+ }
|
|
1029
|
+ }
|
|
1030
|
+
|
828
|
1031
|
}
|
829
|
1032
|
}
|