Пример #1
0
        public static bool CreateDB(bool Test = false)
        {
            MySqlConnection conn = new MySqlConnection(Program.connStr);
            string          s0   = "CREATE DATABASE IF NOT EXISTS aleman_cafe_server DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; " +
                                   "use `aleman_cafe_server`; ";

            s0 += "CREATE TABLE IF NOT EXISTS `products` (" +
                  "`id` INT AUTO_INCREMENT, " +
                  "`name` VARCHAR(255) NOT NULL Unique," +
                  "`type` VARCHAR(255)," +
                  "`price` FLOAT(9,2) DEFAULT '0'," +
                  "`purchasingprice` FLOAT(9,2) DEFAULT '0'," +
                  "`count` Integer(9) DEFAULT '0', " +
                  "`noofsales` Integer(9) DEFAULT '0', " +
                  "`needed` Integer(5) DEFAULT '0', " +
                  "`details` Text, " +
                  "`picurl` Text, " +
                  "PRIMARY KEY(id)); ";
            s0 += "CREATE TABLE IF NOT EXISTS `productslog` (" +
                  "`id` INT(9)," +
                  "`quantity` Integer(9)," +
                  "`price` FLOAT(9,2)," +
                  "`datetime` NUMERIC(21,0)," +
                  "`type` Integer(1)); ";
            s0 += "CREATE TABLE IF NOT EXISTS `timers` (" +
                  "`canuseinternet` Integer(1)," +
                  "`paid` Integer(1)," +
                  "`limitedtime` INT(9)," +
                  "`usedtime` INT(9)," +
                  "`remainingtime` INT(9)," +
                  "`starttime` NUMERIC(21,0)," +
                  "`stopedtime` NUMERIC(21,0)," +
                  "`ip` varchar(50)," +
                  "`macaddress` varchar(55)," +
                  "`hostname` varchar(255) UNIQUE," +
                  "`shownname` varchar(255) UNIQUE," +
                  "`timestatus` Integer(3)," +
                  "`pausedtime` NUMERIC(21,0));";
            ;

            s0 += "CREATE TABLE IF NOT EXISTS `systemlog` (" +
                  "`hostname` VARCHAR(255)," +
                  "`shownname` VARCHAR(255)," +
                  "`price` FLOAT(9,2)," +
                  "`starttime` NUMERIC(21,0)," +
                  "`timestatu` INTEGER(1)," +
                  "`usedtime` Integer(9), " +
                  "PRIMARY KEY(starttime)); ";

            s0 += "CREATE TABLE IF NOT EXISTS `systeminfo` (" +
                  "`user` VARCHAR(255)," +
                  "`pass` VARCHAR(255)," +
                  "`view` VARCHAR(25)," +
                  "`smallicon` INTEGER(1)," +
                  "`grid` INTEGER(1)," +
                  "`statusbar` INTEGER(1)," +

                  "`menubar` INTEGER(1)," +
                  "`RunServerAtStartup` INTEGER(1)," +
                  "`Askpasswordonstartup` INTEGER(1)," +
                  "`EnableUSBPluginWarning` INTEGER(1)," +
                  "`EnableUSBPlugoutWarning` INTEGER(1)," +
                  "`HourPrice` DOUBLE(5,2) DEFAULT '1.50'," +
                  "`MinimumCost` DOUBLE(5,2) DEFAULT '0.50');";

            try
            {
                conn.Open();
                new MySqlCommand(s0, conn).ExecuteNonQuery();
            }
            catch (MySqlException me)
            {
                try { if (conn != null)
                      {
                          conn.Close();
                      }
                } catch { }
                if (!Test)
                {
                    if (Program.isAdmin)
                    {
                        MessageBox.Show(me.Message + Environment.NewLine + Program.connStr);
                    }
                    else
                    {
                        MessageBox.Show(me.Message);
                    }
                }
                else
                {
                    //   MessageBox.Show(me.Message + Environment.NewLine + Program.connStr);
                    DatabaseConfiguration DC = new DatabaseConfiguration(ALEmancafe);
                    DC.ShowDialog();
                    DC.Dispose();
                }
                return(false);
            }
            conn.Close();
            return(true);
            //CreateNewDB();
        }