Ejemplo n.º 1
0
        public void UpdateDatabase(dynamicControlExcelTest.Excel_Use myExcel)//加入新的column所用
        {
            StockDatabase.myExcel = myExcel;
            try
            {
                //  CreatColunm();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            string command = "UPDATE " + myExcel.mySheet[0].Name + " SET ";

            for (int j = 1; j < myExcel.CountExcelHeight; j++)
            {
                command += FirstColumn + ExcelTextOperate(myExcel.mySheet[0].Cells[1, 2].Text)
                           + "=" + ExcelTextOperateForPrice(myExcel.mySheet[0].Cells[j + 1, 2].Text);

                for (int i = 2; i < myExcel.CountExcelWidth; i++)
                {
                    command += ", " + FirstColumn + ExcelTextOperate(myExcel.mySheet[0].Cells[1, i + 1].Text)
                               + "=" + ExcelTextOperateForPrice(myExcel.mySheet[0].Cells[j + 1, 1 + i].Text);
                }

                command += @" where " + FirstColumn + "= '" + myExcel.mySheet[0].Cells[j + 1, 1].Text + @"'";

                nonqueryCommand.CommandText = @"use StockDatabase";
                //Console.WriteLine(nonqueryCommand.CommandText);
                nonqueryCommand.ExecuteNonQuery();
                nonqueryCommand.CommandText = command;
                Console.WriteLine(nonqueryCommand.CommandText);
                nonqueryCommand.ExecuteNonQuery();
                System.Threading.Thread.Sleep(500);
                Console.WriteLine("加入成功");

                command = "UPDATE " + myExcel.mySheet[0].Name + " SET ";
            }
        }
Ejemplo n.º 2
0
        public static void CreateDatabase(dynamicControlExcelTest.Excel_Use myExcel)//創造新的Table
        {
            StockDatabase.myExcel = myExcel;

            float[] tempData;//每筆(整列)資料佔存

            StockDatabase data = new StockDatabase();



            for (int k = 0; k < myExcel.mySheet.Length; k++)
            {
                myExcel.UsingSheet = k;

                #region try creatTable
                try
                {
                    // data.CreatTable(myExcel.mySheet[k].Name);
                }
                catch (Exception ee)
                {
                    Console.WriteLine(ee.Message);
                }
                #endregion

                tempData = new float[myExcel.CountExcelWidth - 1];



                for (int i = 1; i < myExcel.CountExcelHeight; i++)
                {
                    for (int j = 1; j < myExcel.CountExcelWidth; j++)
                    {
                        string tempp = myExcel.mySheet[k].Cells[i + 1, j + 1].Text;

                        try
                        {
                            if (myExcel.mySheet[k].Cells[i + 1, j + 1].Text.CompareTo("-") == 0)
                            {
                                tempData[j - 1] = 0;
                            }
                            else if (myExcel.mySheet[k].Cells[i + 1, j + 1].Text.CompareTo("") == 0)
                            {
                                tempData[j - 1] = 0;
                            }
                            else if (myExcel.mySheet[k].Cells[i + 1, j + 1].Text.CompareTo(" ") == 0)
                            {
                                tempData[j - 1] = 0;
                            }
                            else
                            {
                                tempData[j - 1] = float.Parse(myExcel.mySheet[k].Cells[i + 1, j + 1].Text);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }


                    //data.AddData(myExcel.mySheet[k].Cells[i + 1, 1].Text,, tempData);//加入資料



                    #region TempUseCode//暫時休息 讓CPU不會占用太多資源
                    System.Threading.Thread.Sleep(500);
                    #endregion
                }
            }
        }