예제 #1
0
        private void TempBox_TextChanged(object sender, EventArgs e)
        {
            if (this.UserNoBox.Text.Length < 9)
            {
                return;
            }
            else if (UserNoBox.Text.Length == 10)
            {
                string             strPath      = "D:\\Card License.xlsx";
                Excel.Application  Excel_App1   = new Excel.Application();
                Excel.Workbook     Excel_WB1    = Excel_App1.Workbooks.Open(strPath);
                System.IO.FileInfo xlsAttribute = new FileInfo(strPath);
                xlsAttribute.Attributes = FileAttributes.Normal;
                //Excel.Worksheet Excel_WS1 = new Excel.Worksheet();
                Excel.Worksheet Excel_WS1 = (Excel.Worksheet)Excel_WB1.Worksheets["使用名單與權限"];
                Excel_WB1.Activate();
                Excel_WS1.Activate();

                for (int i = 1; i < 200; i++)
                {
                    Microsoft.Office.Interop.Excel.Range range = (Microsoft.Office.Interop.Excel.Range)Excel_WS1.Cells[i, 1];

                    try
                    {
                        string cellValue = range.Value.ToString();
                        if (cellValue == this.UserNoBox.Text)
                        {
                            Microsoft.Office.Interop.Excel.Range range2 = (Microsoft.Office.Interop.Excel.Range)Excel_WS1.Cells[i, 2];
                            Microsoft.Office.Interop.Excel.Range range3 = (Microsoft.Office.Interop.Excel.Range)Excel_WS1.Cells[i, 3];
                            Microsoft.Office.Interop.Excel.Range range4 = (Microsoft.Office.Interop.Excel.Range)Excel_WS1.Cells[i, 4];
                            string cellValue2 = range2.Value.ToString();
                            //Console.WriteLine(cellValue2);
                            this.DepTextBox.Text = cellValue2;
                            string cellValue3 = range3.Value.ToString();
                            this.UserBox.Text = cellValue3;
                            this.UserNoBox.Hide();
                            this.UserNoLabel.Hide();
                            //this.Userlabel.Hide();
                            string cellvalue4 = range4.Value.ToString();
                            //Console.WriteLine(cellValue3);
                            // Console.Read();
                            string             strPath2      = "D:\\SG64 Utilization Rate.xlsx";
                            Excel.Application  Excel_App2    = new Excel.Application();
                            Excel.Workbook     Excel_WB2     = Excel_App2.Workbooks.Open(strPath2);
                            System.IO.FileInfo xlsAttribute2 = new FileInfo(strPath2);
                            xlsAttribute2.Attributes = FileAttributes.Normal;

                            //Excel.Worksheet Excel_WS1 = new Excel.Worksheet();
                            Excel.Worksheet Excel_WS2 = (Excel.Worksheet)Excel_WB2.Worksheets["RCARD"];
                            Excel_WB2.Activate();
                            Excel_WS2.Activate();
                            Microsoft.Office.Interop.Excel.Range rangeTemp = (Microsoft.Office.Interop.Excel.Range)Excel_WS2.Cells[1, 1];
                            string temp     = rangeTemp.Value.ToString();
                            int    hours    = Int32.Parse(DateTime.Now.ToString("HH"));
                            int    minutes  = Int32.Parse(DateTime.Now.ToString("mm"));
                            int    daynight = 0;
                            string s        = "";
                            if (DateTime.Now.ToString("tt") == "上午")
                            {
                                s = "AM";
                            }
                            else if (DateTime.Now.ToString("tt") == "下午")
                            {
                                s = "PM";
                            }

                            if (hours > 7 && hours < 18)
                            {
                                if (hours == 8)
                                {
                                    if (minutes < 30)
                                    {
                                        daynight = 1;
                                    }
                                    else
                                    {
                                        daynight = 2;
                                    }
                                }
                                else
                                {
                                    daynight = 1;
                                }
                            }
                            else
                            {
                                daynight = 2;
                            }
                            s = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + " " + s;
                            Excel_App2.Cells[rangeTemp, 1] = cellValue2;
                            Excel_App2.Cells[rangeTemp, 2] = cellValue3;
                            Excel_App2.Cells[rangeTemp, 3] = this.ProjectTextBox.Text;
                            Excel_App2.Cells[rangeTemp, 4] = cellvalue4;
                            //Excel_App2.Cells[rangeTemp, 5] = daynight;
                            Excel_App2.Cells[rangeTemp, 6] = s;
                            // Excel_App2.Cells[rangeTemp, 7] = "";
                            // Excel_App2.Cells[1, 1] = Int32.Parse(rangeTemp.Value.ToString()) + 1;
                            Excel_WS2.Application.DisplayAlerts          = false;
                            Excel_WS2.Application.AlertBeforeOverwriting = false;
                            Excel_WB2.Save();
                            Excel_WB2.Close(false, Type.Missing, Type.Missing);
                            ///Excel_WB3.Close(false, Type.Missing, Type.Missing);
                            // Excel_WB1.Close();

                            Excel_App2.Quit();
                            ///Excel_App3.Quit();
                            //   System.Runtime.InteropServices.Marshal.ReleaseComObject(myRrange);
                            // System.Runtime.InteropServices.Marshal.ReleaseComObject(ranfe);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel_WS1);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel_WB1);
                            //System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel_App2);
                            Excel_WS2 = null;
                            Excel_WB2 = null;

                            CPublicMethod.Kill(Excel_App2);
                            /// CPublicMethod.Kill(Excel_App3);
                            GC.Collect();
                            //this.Userlabel.Enabled = false;
                            //this.DepTextBox.Enabled = false;


                            break;
                        }
                    }
                    catch (System.NullReferenceException ex)
                    {
                        //Console.WriteLine("NULL Cell");
                        //Console.Read();
                    }
                }



                // Excel_WB1.Close(false, Type.Missing, Type.Missing);
                ///Excel_WB3.Close(false, Type.Missing, Type.Missing);
                // Excel_WB1.Close();
                Excel_App1.Quit();
                ///Excel_App3.Quit();
                //   System.Runtime.InteropServices.Marshal.ReleaseComObject(myRrange);
                // System.Runtime.InteropServices.Marshal.ReleaseComObject(ranfe);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel_WS1);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel_WB1);
                //System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel_App2);
                Excel_WS1 = null;
                Excel_WB1 = null;

                CPublicMethod.Kill(Excel_App1);
                /// CPublicMethod.Kill(Excel_App3);
                GC.Collect();
            }
        }
예제 #2
0
        void Button_lockClick(object sender, EventArgs e)
        {
            //lookScreenNow();


            if (flag == 0)
            {
                this.Projectlabel.Show();
                //this.Projectlabel.Enabled = false;
                this.ProjectTextBox.Enabled = false;
                this.Userlabel.Show();
                this.Userlabel.Show();
                this.DepLabel.Show();
                this.DepTextBox.Show();
                this.UserNoLabel.Show();
                this.UserBox.Show();
                this.UserNoBox.Show();
                this.UserNoBox.Focus();
                this.Status.Text = "please Use Your Security Card....5s";

                flag = 1;
            }
            else if (flag == 1)
            {
                string             strPath2      = "D:\\SG64 Utilization Rate.xlsx";
                Excel.Application  Excel_App2    = new Excel.Application();
                Excel.Workbook     Excel_WB2     = Excel_App2.Workbooks.Open(strPath2);
                System.IO.FileInfo xlsAttribute2 = new FileInfo(strPath2);
                xlsAttribute2.Attributes = FileAttributes.Normal;

                //Excel.Worksheet Excel_WS1 = new Excel.Worksheet();
                Excel.Worksheet Excel_WS2 = (Excel.Worksheet)Excel_WB2.Worksheets["RCARD"];
                Excel_WB2.Activate();
                Excel_WS2.Activate();
                Microsoft.Office.Interop.Excel.Range rangeTemp = (Microsoft.Office.Interop.Excel.Range)Excel_WS2.Cells[1, 1];
                string temp     = rangeTemp.Value.ToString();
                int    hours    = Int32.Parse(DateTime.Now.ToString("HH"));
                int    minutes  = Int32.Parse(DateTime.Now.ToString("mm"));
                int    daynight = 0;
                string s        = "";
                if (DateTime.Now.ToString("tt") == "上午")
                {
                    s = "AM";
                }
                else if (DateTime.Now.ToString("tt") == "下午")
                {
                    s = "PM";
                }

                if (hours > 7 && hours < 18)
                {
                    if (hours == 8)
                    {
                        if (minutes < 30)
                        {
                            daynight = 1;
                        }
                        else
                        {
                            daynight = 2;
                        }
                    }
                    else
                    {
                        daynight = 1;
                    }
                }
                else
                {
                    daynight = 2;
                }
                s = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss") + " " + s;
                //Excel_App2.Cells[rangeTemp, 1] = cellValue2;
                //Excel_App2.Cells[rangeTemp, 2] = cellValue3;
                //Excel_App2.Cells[rangeTemp, 3] = this.ProjectTextBox.Text;
                //Excel_App2.Cells[rangeTemp, 4] = cellvalue4;
                Excel_App2.Cells[rangeTemp, 5] = daynight;
                //Excel_App2.Cells[rangeTemp, 6] = s;
                Excel_App2.Cells[rangeTemp, 7]               = s;
                Excel_App2.Cells[1, 1]                       = Int32.Parse(rangeTemp.Value.ToString()) + 1;
                Excel_WS2.Application.DisplayAlerts          = false;
                Excel_WS2.Application.AlertBeforeOverwriting = false;
                Excel_WB2.Save();
                Excel_WB2.Close(false, Type.Missing, Type.Missing);
                ///Excel_WB3.Close(false, Type.Missing, Type.Missing);
                // Excel_WB1.Close();

                Excel_App2.Quit();
                ///Excel_App3.Quit();
                //   System.Runtime.InteropServices.Marshal.ReleaseComObject(myRrange);
                // System.Runtime.InteropServices.Marshal.ReleaseComObject(ranfe);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel_WS2);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel_WB2);
                //System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel_App2);
                Excel_WS2 = null;
                Excel_WB2 = null;

                CPublicMethod.Kill(Excel_App2);
                /// CPublicMethod.Kill(Excel_App3);
                GC.Collect();
                this.Userlabel.Hide();
                this.Userlabel.Hide();
                this.DepLabel.Hide();
                this.DepTextBox.Hide();
                this.UserNoLabel.Hide();
                this.UserBox.Hide();
                this.UserNoBox.Hide();
                this.ProjectTextBox.Enabled = Enabled;
                this.DepTextBox.Enabled     = Enabled;
                this.Userlabel.Enabled      = Enabled;
                this.UserBox.Enabled        = Enabled;
                this.UserNoBox.Text         = "";
                this.DepTextBox.Text        = "";
                this.UserBox.Text           = "";
                flag = 0;
            }
            else
            {
                return;
            }



            //MessageBox.Show("123");
            //this.DepLabel.Enabled = false;
            //this.DepLabel.Hide();
            //this.Userlabel.Hide();
            //this.DepTextBox.Hide();
            //this.UserBox.Hide();
            //this.UserNoBox.Show();
            //this.TempBox.Hide();
            //this.TempBox.Enabled = false;
            //this.UserNoBox.Focus();
            //this.UserNoBox.Select();
            //Thread.Sleep(3000);

            /* this.TempBox.Select(TempBox.SelectionStart, 0);
             * TempBox.ScrollToCaret();
             * if (this.TempBox.Text == "0107110550\n")
             *   MessageBox.Show("123");*/
        }