Browse Source

Table Excel 추가 /Excell Killl 기능 추가

PYJ 5 years ago
parent
commit
f8cfa64c0c

BIN
.vs/Jdas_Mbic/v15/.suo


BIN
.vs/Jdas_Mbic/v15/Server/sqlite3/storage.ide


BIN
.vs/Jdas_Mbic/v15/Server/sqlite3/storage.ide-shm


BIN
.vs/Jdas_Mbic/v15/Server/sqlite3/storage.ide-wal


+ 14 - 0
Jdas_Mbic/Func/Bluecell_BootProtocol.cs

@@ -71,7 +71,21 @@ namespace Jdas_Mbic
71 71
             temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1]     = BLUECELL_TAILER;
72 72
             this.serial.Serial_DataSend(temp_buf, temp_buf.Length);
73 73
         }
74
+        public void Bluecell_RF_Status_Req(object serial)
75
+        {
76
+            Crc16 crc16 = new Crc16();
77
+            this.serial = (Serial)serial;
78
+            byte[] temp_buf = new byte[6];
74 79
 
80
+            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Header] = BLUECELL_HEADER;
81
+            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Type] = 77;
82
+            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_Length] = Convert.ToByte(temp_buf.Length - 3);
83
+            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_CrcIndex] = Convert.ToByte(temp_buf.Length - 2);
84
+            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 0] = crc16.STH30_CreateCrc(temp_buf, temp_buf[2]);
85
+            temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 1] = BLUECELL_TAILER;
86
+            this.serial.Serial_DataSend(temp_buf, temp_buf.Length);
87
+
88
+        }
75 89
         public const byte bluecell_length    = 2;
76 90
         public const byte bluecell_updatecnt = 2;
77 91
         public const byte bluecell_crc16     = 2;

+ 29 - 1
Jdas_Mbic/Jdas_Mbic.csproj

@@ -125,6 +125,34 @@
125 125
   <ItemGroup>
126 126
     <None Include="Resources\TX_Red_Image.png" />
127 127
   </ItemGroup>
128
-  <ItemGroup />
128
+  <ItemGroup>
129
+    <COMReference Include="Microsoft.Office.Core">
130
+      <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
131
+      <VersionMajor>2</VersionMajor>
132
+      <VersionMinor>8</VersionMinor>
133
+      <Lcid>0</Lcid>
134
+      <WrapperTool>primary</WrapperTool>
135
+      <Isolated>False</Isolated>
136
+      <EmbedInteropTypes>True</EmbedInteropTypes>
137
+    </COMReference>
138
+    <COMReference Include="Microsoft.Office.Interop.Excel">
139
+      <Guid>{00020813-0000-0000-C000-000000000046}</Guid>
140
+      <VersionMajor>1</VersionMajor>
141
+      <VersionMinor>9</VersionMinor>
142
+      <Lcid>0</Lcid>
143
+      <WrapperTool>primary</WrapperTool>
144
+      <Isolated>False</Isolated>
145
+      <EmbedInteropTypes>True</EmbedInteropTypes>
146
+    </COMReference>
147
+    <COMReference Include="VBIDE">
148
+      <Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
149
+      <VersionMajor>5</VersionMajor>
150
+      <VersionMinor>3</VersionMinor>
151
+      <Lcid>0</Lcid>
152
+      <WrapperTool>primary</WrapperTool>
153
+      <Isolated>False</Isolated>
154
+      <EmbedInteropTypes>True</EmbedInteropTypes>
155
+    </COMReference>
156
+  </ItemGroup>
129 157
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
130 158
 </Project>

File diff suppressed because it is too large
+ 362 - 226
Jdas_Mbic/Main.Designer.cs


+ 205 - 2
Jdas_Mbic/Main.cs

@@ -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
 }

+ 9 - 0
Jdas_Mbic/Main.resx

@@ -1359,7 +1359,16 @@
1359 1359
   <metadata name="Column_Offset.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
1360 1360
     <value>True</value>
1361 1361
   </metadata>
1362
+  <metadata name="Column_DB.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
1363
+    <value>True</value>
1364
+  </metadata>
1365
+  <metadata name="Column_Offset.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
1366
+    <value>True</value>
1367
+  </metadata>
1362 1368
   <metadata name="timer_JdasMbic.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
1363 1369
     <value>27, 11</value>
1364 1370
   </metadata>
1371
+  <metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
1372
+    <value>164, 11</value>
1373
+  </metadata>
1365 1374
 </root>

BIN
Jdas_Mbic/bin/Debug/ATT_DL1.xls


BIN
Jdas_Mbic/bin/Debug/ATT_DL2.xls


BIN
Jdas_Mbic/bin/Debug/ATT_DL3.xls


BIN
Jdas_Mbic/bin/Debug/ATT_DL4.xls


BIN
Jdas_Mbic/bin/Debug/ATT_UL1.xls


BIN
Jdas_Mbic/bin/Debug/ATT_UL2.xls


BIN
Jdas_Mbic/bin/Debug/ATT_UL3.xls


BIN
Jdas_Mbic/bin/Debug/ATT_UL4.xls


BIN
Jdas_Mbic/bin/Debug/DET_DL1.xls


BIN
Jdas_Mbic/bin/Debug/Jdas_Mbic.exe


BIN
Jdas_Mbic/bin/Debug/Jdas_Mbic.pdb


BIN
Jdas_Mbic/bin/Debug/TEMP_UL4.xls


BIN
Jdas_Mbic/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache


+ 1 - 1
Jdas_Mbic/obj/Debug/Jdas_Mbic.csproj.CoreCompileInputs.cache

@@ -1 +1 @@
1
-635e4eca58ca169a641e3428ecd29e2a2f0f5fbc
1
+a0e135a49a434b394a1b2ba0915f88a4bd649a39

+ 1 - 0
Jdas_Mbic/obj/Debug/Jdas_Mbic.csproj.FileListAbsolute.txt

@@ -22,3 +22,4 @@ D:\C#\Jdas_Mbic\Jdas_Mbic\obj\Debug\Jdas_Mbic.Debug.resources
22 22
 D:\C#\Jdas_Mbic\Jdas_Mbic\obj\Debug\Jdas_Mbic.Download_bar.resources
23 23
 G:\C#\Jdas_Mbic\Jdas_Mbic\obj\Debug\Jdas_Mbic.Debug.resources
24 24
 G:\C#\Jdas_Mbic\Jdas_Mbic\obj\Debug\Jdas_Mbic.Download_bar.resources
25
+D:\C#\Jdas_Mbic\Jdas_Mbic\obj\Debug\Jdas_Mbic.csproj.ResolveComReference.cache

BIN
Jdas_Mbic/obj/Debug/Jdas_Mbic.csproj.GenerateResource.cache


BIN
Jdas_Mbic/obj/Debug/Jdas_Mbic.csproj.ResolveComReference.cache


BIN
Jdas_Mbic/obj/Debug/Jdas_Mbic.exe


BIN
Jdas_Mbic/obj/Debug/Jdas_Mbic.pdb