Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            string database = txt_database.Text.Trim();
            string root     = @txt_saveurl.Text.Trim();
            string contents = null;

            contents += DateTime.Now.ToString("yyyy.MM.dd-HH:mm:ss:");
            contents += "创建数据库" + database + ",";
            if (root != string.Empty)
            {
                if (database != "")
                {
                    if (!CreateDataBase.boolDataExists(database))
                    {
                        if (CreateDataBase.CreateDataBaseDB(database, root))
                        {
                            MessageBox.Show("创建成功!");
                            BindDropDownList();
                            contents += "创建成功!";
                        }
                        else
                        {
                            MessageBox.Show("发生错误!");
                            contents += "发生错误!";
                        }
                    }
                    else
                    {
                        MessageBox.Show("已有同名数据库!");
                        contents += "已有同名数据库!";
                    }
                    ouputtext(contents);
                }
                else
                {
                    this.txt_database.Focus();
                }
                readtextfrompath();
            }
            else
            {
                MessageBox.Show("尚未选择路径!");
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string websitename = getWebsitePath(textBox2.Text);
            string newpath     = websitename + "\\" + (textBox4.Text.Substring(textBox4.Text.LastIndexOf("\\") + 1));

            if (string.IsNullOrEmpty(txt_websitename.Text) || string.IsNullOrEmpty(textBox3.Text))
            {
                MessageBox.Show("网站名或路径不能为空");
                return;
            }
            button1.Enabled = false;
            label4.Text     = "开始生成";

            string dataname = getdatabasename(txt_websitename.Text);
            string root     = null;

            if (textBox6.Text == "地址3" || textBox6.Text == string.Empty)
            {
                root = websitename + "\\" + "数据库";
            }
            else
            {
                root = textBox6.Text;
            }

            #region 创建新的网站路径并复制网站到新地址
            //创建新的网站路径
            var createWebsite = Task <int> .Factory.StartNew(() =>
            {
                if (!string.IsNullOrEmpty(newpath))
                {
                    try
                    {
                        createWebsitePath(newpath);
                        return(1);
                    }
                    catch (Exception)
                    {
                        return(0);
                    }
                }
                else
                {
                    return(-1);
                }
            });

            //复制网站到新地址
            var relcopy = createWebsite.ContinueWith(t =>
            {//F:\工作\前端页面\玖点
                try
                {
                    relcopyfirstfiles(textBox4.Text, newpath);
                    return(1);
                }
                catch (Exception)
                {
                    return(0);
                }
            });
            #endregion

            #region 生成数据库
            var createDatabase = new Task <int>(() =>
            {
                try
                {
                    Directory.CreateDirectory(root);
                    try
                    {
                        CreateDataBase.CreateDataBaseDB(dataname, root);
                        execfile(dataname, textBox5.Text);
                        return(1);
                    }
                    catch (Exception ex)
                    {
                        string s = ex.Message;
                        return(0);
                    }
                }
                catch { return(0); }
            });
            #endregion
            #region 创建动态页面
            var createHtmlContent = new Task <int>(() =>
            {
                try
                {
                    if (chb_checkpagec.Checked)
                    {
                        //初始化静态网页参数
                        ContentFormHtml(textBox3.Text + @"\index.html");
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch { return(0); }
            });
            //生成动态页面
            var createNewWebsites = createHtmlContent.ContinueWith(c =>
            {
                string webpath = newpath + "\\" + "web";
                try
                {
                    foreachdiectory(webpath);
                }
                catch
                {
                    return(0);
                }
                try
                {
                    createnewwebsite(webpath, textBox3.Text);
                    updatexmldoc(webpath + @"\web.config", "server=(local);DataBase=" + dataname + ";uid=sa;pwd=123456;");

                    //修改端口号
                    ReadXMLdoc xml = new ReadXMLdoc();
                    int localhost  = Convert.ToInt32(xml.readtext("Localhost"));
                    localhost      = localhost + 1;
                    xml.updatexmldoc("Localhost", localhost.ToString());


                    string strFilePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, newpath + @"\InvincibleCMS.sln");
                    if (File.Exists(strFilePath))
                    {
                        string strContent = File.ReadAllText(strFilePath);
                        strContent        = Regex.Replace(strContent, "18000", localhost.ToString());
                        File.WriteAllText(strFilePath, strContent);
                    }

                    return(1);
                }
                catch
                {
                    return(0);
                }
            });

            #endregion
            //进度条线程
            var progresstask = Task.Factory.StartNew(() =>
            {
                createWebsite.Wait();//等待网站创建完成
                if (createWebsite.Result == 1)
                {
                    Init(1, 16, "网站新路径创建成功", new Random().Next(50, 100));
                    Thread.Sleep(500);

                    Inits(16, 70, "正在复制文件", new Random().Next(50, 100), relcopy);

                    relcopy.Wait();//等待复制文件完成
                    if (relcopy.Result == 1)
                    {
                        createDatabase.Start();    //开始创建数据库
                        createHtmlContent.Start(); //开始生成页面

                        Inits(70, 75, "初始化静态网页参数中", new Random().Next(50, 100), createDatabase);
                        if (createDatabase.Result == 1)
                        {
                            Init(74, 76, "数据库创建成功", new Random().Next(50, 100));
                        }
                        Init(75, 77, "复制文件成功", new Random().Next(100, 200));
                        Thread.Sleep(500);

                        Inits(76, 90, "初始化静态网页参数中", new Random().Next(50, 100), createHtmlContent);

                        createHtmlContent.Wait();//初始化静态网页参数完成
                        Init(89, 91, "初始化静态网页参数完成", new Random().Next(50, 100));
                        Thread.Sleep(500);

                        Inits(91, 100, "动态网页生成中", new Random().Next(50, 100), createNewWebsites);

                        createNewWebsites.Wait();//动态网页生成完成
                        Init(99, 101, "动态网页生成完成", new Random().Next(50, 100));
                        button1.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show("发生错误");
                    }
                }
                else
                {
                    MessageBox.Show("发生错误");
                }
            });
        }
Beispiel #3
0
        private string newwebpath = null;//传递窗体参数
        private void button12_Click(object sender, EventArgs e)
        {
            string websitename = getWebsitePath(textBox2.Text);
            string newpath     = websitename + "\\" + (textBox4.Text.Substring(textBox4.Text.LastIndexOf("\\") + 1));

            if (!string.IsNullOrEmpty(newpath))
            {
                if (createWebsitePath(newpath))
                {
                    relcopyfirstfiles(textBox4.Text, newpath);
                    string webpath = newpath + "\\" + "web";
                    newwebpath = webpath;
                    if (Directory.Exists(webpath))
                    {
                        try
                        {
                            foreachdiectory(webpath);
                        }
                        catch
                        {
                            MessageBox.Show("操作失败");
                            return;
                        }
                        finally
                        {
                            if (chb_checkpagec.Checked)
                            {
                                //初始化静态网页参数
                                ContentFormHtml(textBox3.Text + @"\index.html");
                            }
                            createnewwebsite(webpath, textBox3.Text);

                            //修改端口号
                            //ReadXMLdoc xml = new ReadXMLdoc();
                            //int localhost = Convert.ToInt32(xml.readtext("Localhost"));
                            //localhost = localhost + 1;
                            //xml.updatexmldoc("Localhost", localhost.ToString());


                            //string strFilePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, newpath + @"\InvincibleCMS.sln");
                            //if (File.Exists(strFilePath))
                            //{
                            //    string strContent = File.ReadAllText(strFilePath);
                            //    strContent = Regex.Replace(strContent, "17987", localhost.ToString());
                            //    File.WriteAllText(strFilePath, strContent);
                            //}


                            string dataname = getdatabasename(txt_websitename.Text);
                            //修改数据库名
                            updatexmldoc(webpath + @"\web.config", "server=(local);DataBase=" + dataname + ";uid=sa;pwd=123456");

                            string root = null;
                            if (textBox6.Text == "地址3" || textBox6.Text == string.Empty)
                            {
                                root = websitename + "\\" + "数据库";
                                if (!Directory.Exists(root))
                                {
                                    Directory.CreateDirectory(root);
                                }
                            }
                            else
                            {
                                root = textBox6.Text;
                            }
                            if (CreateDataBase.CreateDataBaseDB(dataname, root))
                            {
                                execfile(dataname, textBox5.Text);


                                MessageBox.Show("操作成功!");
                            }
                            else
                            {
                                MessageBox.Show("操作失败!");
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("创建失败");
                }
            }
            else
            {
                MessageBox.Show("网站名不能为空");
            }
        }