예제 #1
0
        private void XoaSachBang()
        {
            string      delete = "Delete from tblPGN";
            clsDatabase cls    = new clsDatabase();

            cls.Execute_NonQuery(delete);
        }
예제 #2
0
        private string GetData(ref DataTable dt, string StoreProcedureName)
        {
            try
            {
                string[]    Values = new string[] { textBox1.Text.Trim() };
                clsDatabase cls    = new clsDatabase();
                cls.OpenConnect();
                if (Paras.Length != Values.Length)
                {
                    return("Tham bien va tham tri khong tuong thich");
                }
                else
                {
                    cls.getValue(ref dt, StoreProcedureName, Paras, Values);
                }

                cls.CloseConnect();
            }
            catch (Exception ex)
            {
                error = ex.Message;
                MessageBox.Show("Co loi " + ex.Message);
            }
            return(error);
        }
예제 #3
0
 private void ReadFromDatabaseToForm(string TableName)
 {
     try
     {
         clsDatabase cls     = new clsDatabase();
         string[]    TextArr = cls.ReadFromTable(TableName);
         int         i       = 0;
         foreach (string textline in TextArr)
         {
             i++;
             if ((i % 11) == 0)
             {
                 richTextBox1.Text += textline + "\n\n";
             }
             else
             {
                 richTextBox1.Text += textline + "\n";
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #4
0
        private void SaveFormToDatabase(string Tablename)
        {
            try
            {
                if (richTextBox1.Text.Trim() == "")
                {
                    MessageBox.Show("rickTextBox CHUA CO NOI DUNG!");
                    return;
                }
                string      sql = " SELECT * FROM information_schema.tables where table_name ='" + Tablename + "'";
                clsDatabase cls = new clsDatabase();
                int         kq  = cls.Execute_Scalar(sql);
                if (kq == 0)
                {
                    string createTable = "USE [WORK_WITH_PGN_FILE]" +
                                         "GO" +
                                         /****** Object:  Table [dbo].[tblPGN]    Script Date: 10/02/2014 11:18:14 ******/
                                         "SET ANSI_NULLS ON" +
                                         "GO" +
                                         "vSET QUOTED_IDENTIFIER ON" +
                                         "GO" +
                                         "CREATE TABLE [dbo].[" + Tablename + "](" +
                                         "[ID] [bigint] IDENTITY(1,1) NOT NULL," +
                                         "[Events] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         " [Site] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         "[Date] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         "[Rounds] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         "[White] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         "[Black] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         " [Result] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         "[WhiteElo] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         "[BlackElo] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         "[ECO] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         " [Plays] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL," +
                                         "CONSTRAINT [PK_tblPGN] PRIMARY KEY CLUSTERED " +
                                         "(" +
                                         " [ID] ASC" +
                                         ")WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]" +
                                         ") ON [PRIMARY]";
                    cls.Execute_NonQuery(createTable);
                }
                string[] ReadFromRickTextBox = richTextBox1.Text.Trim().Split('\n');

                string[] Output = ExecuteStringArray(ReadFromRickTextBox);
                SaveStringToDatabase(Output, Tablename);
                MessageBox.Show("Thanh Cong!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #5
0
 private void SaveStringToDatabase(string[] StringName, string TableName)
 {
     try
     {
         string[] Paras = new string[11] {
             "@Events", "@Site", "@Date", "@Rounds", "@White", "@Black", "@Result", "@WhiteElo", "@BlackElo", "@ECO", "@Plays"
         };
         int _Count = 0;
         foreach (string file in StringName)
         {
             _Count++;
             string strResult = "";
             if ((_Count % 11) == 0)
             {
                 Values[0]  = StringName[_Count - 11];
                 Values[1]  = StringName[_Count - 10];
                 Values[2]  = StringName[_Count - 9];
                 Values[3]  = StringName[_Count - 8];
                 Values[4]  = StringName[_Count - 7];
                 Values[5]  = StringName[_Count - 6];
                 Values[6]  = StringName[_Count - 5];
                 Values[7]  = StringName[_Count - 4];
                 Values[8]  = StringName[_Count - 3];
                 Values[9]  = StringName[_Count - 2];
                 Values[10] = StringName[_Count - 1];
                 clsDatabase cls = new clsDatabase();
                 cls.OpenConnect();
                 cls.ExecuteSP("InsertTotblPGN", Paras, Values, ref strResult);
                 //MessageBox.Show(strResult);
                 cls.CloseConnect();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #6
0
        private void ChonVan(int Maso)
        {
            try
            {
                if (textBox1.Text.Trim() == "")
                {
                    MessageBox.Show("Chua chon Ten Nguoi");
                    return;
                }

                switch (Maso)
                {
                //XỬ LÝ THEO CÁCH CŨ LÀ GETDATA RA TBL RỒI ĐỌC TỪ TBL RA RICKTEXTBOX1 RẤT CHẬM, MẤT RẤT NHIỀU THỜI GIAN.
                // SAU KHI THAY THẾ BẰNG SỬ DỤNG EXECUTEREADER THÌ TỐC ĐỘ NHANH HƠN RẤT NHIỀU, ĐÁNG ĐỂ XEM XÉT LẠI!!!!!!!!
                case 1:
                {
                    //clsDatabase cls = new clsDatabase();
                    //cls.getValue(ref tbl, "SPChonVanHoa", Paras, Values);
                    richTextBox1.Text = "";
                    clsDatabase cls = new clsDatabase();
                    richTextBox1.Text = cls.Execute_Reader("SPChonVanHoa", textBox1.Text.Trim());
                    //GetData(ref tbl, "SPChonVanHoa");
                    //ReadFromDataTableToForm(tbl);
                    break;
                }

                case 2:
                {
                    //clsDatabase cls = new clsDatabase();
                    //cls.getValue(ref tbl, "SPChonVanThang", Paras, Values);
                    richTextBox1.Text = "";
                    clsDatabase cls = new clsDatabase();
                    richTextBox1.Text = cls.Execute_Reader("SPChonVanThang", textBox1.Text.Trim());
                    //label3.Text = "ĐANG XỬ LÝ...";
                    //GetData(ref tbl, "SPChonVanThang");
                    //ReadFromDataTableToForm(tbl);

                    break;
                }

                case 3:
                {
                    //clsDatabase cls = new clsDatabase();
                    //cls.getValue(ref tbl, "SPChonVanThua", Paras, Values);
                    richTextBox1.Text = "";
                    clsDatabase cls = new clsDatabase();
                    richTextBox1.Text = cls.Execute_Reader("SPChonVanThua", textBox1.Text.Trim());

                    //GetData(ref tbl, "SPChonVanThua");
                    //ReadFromDataTableToForm(tbl);
                    break;
                }

                    //default:

                    //        MessageBox.Show("CO LOI XAY RA TRONG QUA TRINH LUA CHON");
                }

                MessageBox.Show("Xong!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }