Пример #1
0
        /// <summary>
        /// ファイル(ogg,wav)の読み込み。
        /// </summary>
        /// <param name="name"></param>
        /// <param name="ch">
        /// 読み込むチャンクを指定。ch=0なら自動で空きを探す 1~8</param>
        /// <returns></returns>
        private YanesdkResult LoadChunk(string name, int ch)
        {
            if (NoSound)
            {
                return(YanesdkResult.PreconditionError);
            }
            SDL_RWopsH rwops = FileSys.ReadRW(name);

            if (rwops.Handle != IntPtr.Zero)
            {
                chunk = SDL.Mix_LoadWAV_RW(rwops.Handle, 1);
            }
            else
            {
                return(YanesdkResult.FileNotFound);                     // file not found
            }
            if (chunk == IntPtr.Zero)
            {
                return(YanesdkResult.FileReadError);                    // 読み込みに失敗してやんの
            }
            chunkChannel = ch;

            CacheSystem.OnResourceChanged(this);

            return(YanesdkResult.NoError);
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            com.adminLogin();
            if (!IsPostBack)
            {
                string lbid = pg.request("lbid");
                if (lbid == "")
                {
                    lbid = "0";
                }
                if (lbid != "")
                {
                    lbname      = clsLB.getLbname(lbid);
                    hLbid.Value = lbid;
                }

                string act = pg.request("act");
                if (act == "top")
                {
                    //置顶
                    List <DXProd> prods = (from pro in dbContext.DXProd where pro.lbid == Int32.Parse(lbid) select pro).ToList <DXProd>();
                    foreach (var item in prods)
                    {
                        item.isTop = false;
                    }
                    dbContext.SubmitChanges();

                    DXProd pro_ = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(pg.request("id")) select pro).First <DXProd>();
                    pro_.isTop = true;
                    dbContext.SubmitChanges();
                    return;
                }

                if (act == "IsIndex")
                {
                    //置顶
                    DXProd pro_ = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(pg.request("id")) select pro).First <DXProd>();
                    pro_.isIndex = true;
                    dbContext.SubmitChanges();
                    alert.showAndGo("设置成功", "Prod.aspx?lbid=" + lbid);
                    return;
                }
                if (act == "del")
                {
                    string id   = pg.request("id");
                    DXProd pro_ = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(pg.request("id")) select pro).First <DXProd>();
                    //删除图片
                    FileSys.delFile(pro_.pic);
                    FileSys.delFile(pro_.picSmall);
                    FileSys.delFile(pro_.pic.Replace(".jpg", "_s.jpg"));

                    //删除
                    dbContext.DXProd.DeleteOnSubmit(dbContext.DXProd.Single(c => c.Id == Int32.Parse(id)));

                    alert.showAndGo("删除成功", "Prod.aspx?lbid=" + lbid);
                    return;
                }
                bindGv();
            }
        }
Пример #3
0
        /// <summary>创建系统配置</summary>
        public static void CreateSysConfig()
        {
            wapp.AppList.SaveConfigPath = wapp.AppList.AppBasePath + wapp.AppList.AppFilesDirName + "\\";
            FileSys.NewDir(wapp.AppList.SaveConfigPath);
            wapp.AppList.LogSavePath = wapp.AppList.AppBasePath + wapp.AppList.SaveLogDirName + "\\";
            FileSys.NewDir(wapp.AppList.LogSavePath);
            _UserLoginTable  = wapp.AppList.GetConfigDataTable(wapp.AppList.UserLoginTableName);
            _UserConifgTable = wapp.AppList.GetConfigDataTable(wapp.AppList.UserConifgTableName);
            _SystemInfo      = wapp.AppList.GetConfigDataTable(wapp.AppList.SystemInfoName);
            string spath = wapp.AppList.SaveConfigPath + _SystemInfo.TableName + ".xml";

            if (File.Exists(spath))
            {
                File.Delete(spath);
            }
            DataRow newRow = _SystemInfo.NewRow();

            newRow["SystemName"]    = SystemName;
            newRow["SystemTitle"]   = wapp.AppList.SystemShowName;
            newRow["SystemVers"]    = SystemVers;
            newRow["SystemVersion"] = SystemVersion;
            newRow["SystemVerNum"]  = SystemVerNum;
            newRow["PublishDate"]   = SystemPublishDate;
            newRow["SystemInfo"]    = wapp.AppList.SystemShowName;
            newRow["CreateDate"]    = SystemCreateDate;
            _SystemInfo.Rows.Add(newRow);
            _SystemInfo.WriteXml(spath, XmlWriteMode.WriteSchema);
        }
Пример #4
0
        private void btoper_Click(object sender, EventArgs e)
        {
            Encoding      en    = Encoding.Default;
            StringBuilder strb  = new StringBuilder();
            string        path  = tBdir.Text;
            string        spath = tBsave.Text;
            List <string> paths = new List <string>();
            List <string> files = new List <string>();

            FileSys.GetAllDirFiles(path, ref files, ref paths, "*.txt");
            for (int i = 0; i < files.Count; i++)
            {
                string fpath = files[i];
                en = GetFileEncoding(fpath);
                StreamReader rd      = new StreamReader(fpath, en);
                string       StrRead = rd.ReadToEnd().ToString();
                StrRead = Filtrate(StrRead);
                strb.Append(StrRead);
            }
            FileStream fs = File.Create(spath);

            byte[] bContent = en.GetBytes(strb.ToString());
            fs.Write(bContent, 0, bContent.Length);
            fs.Close();
        }
Пример #5
0
        protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string     newsID = GV.DataKeys[e.RowIndex].Value.ToString();
            SQLHelper_ db     = new SQLHelper_();

            db.sql = "SELECT pic FROM " + com.tablePrefix + "News WHERE NewsID=" + newsID;
            DataTable dt = db.Get_DataTable();

            if (dt.Rows.Count > 0)
            {
                FileSys.delFile(dt.Rows[0]["pic"].ToString());
            }
            //删除相册中的照片
            db.sql = @"SELECT *
FROM " + com.tablePrefix + "News  WHERE ParentNewsID=" + newsID;
            dt     = new DataTable();
            dt     = db.Get_DataTable();
            foreach (DataRow dr in dt.Rows)
            {
                FileSys.delFile(dr["pic"].ToString());
            }
            db.sql = "DELETE News WHERE ParentNewsID=" + newsID;
            db.ExecSql();
            db.sql = "DELETE News WHERE NewsID=" + newsID;
            db.ExecSql();
            bindGv();
            alert.Show(Page, "删除成功");
        }
Пример #6
0
        // 大文字小文字違いだけのものはCLSに準拠しない(´ω`)

        /// <summary>
        /// 定義ファイルを読み込む
        ///
        /// 定義ファイルに書いてあるファイル名が実行ファイルからの相対pathなのか、それとも
        /// 定義ファイルの存在するフォルダからの相対pathなのかどうかは、
        /// IsDefRelativePathオプションに従う。
        /// </summary>
        public YanesdkResult LoadDefFile(string filename)
        {
            Release();

            basePath = FileSys.GetDirName(filename);
            YanesdkResult result = reader.LoadDefFile(filename, OptNum);

            if (result == YanesdkResult.NoError)
            {
                Dictionary <int, FilenamelistReader.Info> .KeyCollection
                    keys = reader.Data.Keys;
                foreach (int key in keys)
                {
                    // ファイル名は定義ファイル相対pathならそのようにする
                    if (IsDefRelativePath)
                    {
                        reader.Data[key].name =
                            FileSys.MakeFullName(basePath, reader.Data[key].name);
                    }

                    ICachedObject obj = OnDefFileLoaded(reader.Data[key]);
                    dict.Add(key, obj);
                }
            }
            return(result);
        }
Пример #7
0
        public void ToFileInfo_Works_As_Expected()
        {
            var          filename = nameof(StringUnsafeTest);
            var          folder   = FileSys.TestFolderNonExisting().FullName;
            const string ext      = "json";

            var fileInfo1 = folder.ToFileInfo(filename, ext);
            var fileInfo2 = folder.ToFileInfo(filename + "." + ext);
            var fileInfo3 = Path.Combine(folder, filename + "." + ext).ToFileInfo();

            Assert.False(fileInfo1.Exists);
            Assert.False(fileInfo2.Exists);
            Assert.False(fileInfo3.Exists);

            Assert.True(fileInfo1.FullName.Equals(fileInfo2.FullName));
            Assert.True(fileInfo1.FullName.Equals(fileInfo3.FullName));

            Assert.True(fileInfo1.Extension.TrimSafeOrNull('.').Equals(ext));
            Assert.True(fileInfo2.Extension.TrimSafeOrNull('.').Equals(ext));
            Assert.True(fileInfo3.Extension.TrimSafeOrNull('.').Equals(ext));

            Assert.NotNull(fileInfo1.Directory);
            Assert.NotNull(fileInfo2.Directory);
            Assert.NotNull(fileInfo3.Directory);

            Assert.True(fileInfo1.Directory.FullName.Equals(folder));
            Assert.True(fileInfo2.Directory.FullName.Equals(folder));
            Assert.True(fileInfo3.Directory.FullName.Equals(folder));
        }
Пример #8
0
        public MiswGame2008(bool fullscreen, int startLevel)
        {
            FileArchiverZip zip = new FileArchiverZip();

            zip.ZipExtName = ".bin";
            FileSys.AddArchiver(zip);
            window = new SDLWindow();
            window.SetCaption("DTF");
            window.BeginScreenTest();
            if (fullscreen)
            {
                window.TestVideoMode(640, 480, 32);
                window.TestVideoMode(640, 480, 16);
            }
            else
            {
                window.TestVideoMode(640, 480, 0);
            }
            window.EndScreenTest();
            graphics = new SdlGraphics(window);
            audio    = new SdlAudio();
            input    = new SdlInput(fullscreen);

            this.startLevel = startLevel;
        }
Пример #9
0
 /// <summary>根据文件名与指定后缀组返回随机生成的文件名</summary>
 /// <param name="fileName">文件名</param>
 /// <param name="ext">后缀名组,多个后缀使用|分隔(例如:jpg|gif|jpeg)</param>
 /// <returns>根据文件名与指定后缀组返回随机生成的文件名</returns>
 public static string GetFileName(string fileName, string ext)
 {
     if (Often.IsExt(fileName, ext))
     {
         string exts = FileSys.GetFileExtension(fileName);
         return(Often.GetLongAddup() + "." + exts);
     }
     return("");
 }
Пример #10
0
        public void ToDirectoryInfo_With_Given_SubPath_Works_As_Expected(bool create)
        {
            var directory     = FileSys.TestFolderNonExisting();
            var withSubPathDi = directory.FullName.ToDirectoryInfo(new[] { "SubPathTest1" }, create);

            directory.Refresh();

            Assert.True(withSubPathDi.Exists == create);
            Assert.True(directory.Exists == create);
            Assert.True(withSubPathDi.FullName.Equals(Path.Combine(directory.FullName, "SubPathTest1")));
        }
Пример #11
0
        public void ToDirectoryInfo_With_FullPath_Works_As_Expected(bool create)
        {
            var directory     = FileSys.TestFolderNonExisting();
            var withSubPathDi = directory.FullName.ToDirectoryInfo(create);

            directory.Refresh();

            Assert.True(withSubPathDi.Exists == create);
            Assert.True(directory.Exists == create);
            Assert.True(withSubPathDi.FullName.Equals(directory.FullName));
        }
Пример #12
0
        public StageData(string path, bool bossStage)
        {
            this.path = path;
            string[] stageData;
            int      currentLine;

            try
            {
                stageData   = Regex.Split(Encoding.ASCII.GetString(FileSys.Read(path)), @"\r\n?|\n");
                currentLine = 0;
            }
            catch
            {
                throw new Exception("ステージデータ「" + path + "」を読み込めません><");
            }
            try
            {
                numRows = int.Parse(stageData[currentLine]);
                currentLine++;
                numCols = int.Parse(stageData[currentLine]);
                currentLine++;
            }
            catch
            {
                throw new Exception("ステージデータ「" + path + "」の第" + (currentLine + 1) + "行のマップのサイズの指定がおかしいです><");
            }
            mapData = new string[numRows];
            for (int row = 0; row < numRows; row++)
            {
                try
                {
                    mapData[row] = stageData[currentLine];
                    currentLine++;
                }
                catch (IndexOutOfRangeException)
                {
                    throw new Exception("ステージデータ「" + path + "」の高さが指定されたものに一致しません><");
                }
                if (mapData[row].Length != numCols)
                {
                    throw new Exception("ステージデータ「" + path + "」の第" + (currentLine + 1) + "行の幅が指定されたものに一致しません><");
                }
            }
            List <string[]> thingDataList = new List <string[]>();

            while (currentLine < stageData.Length)
            {
                thingDataList.Add(stageData[currentLine].Split(' '));
                currentLine++;
            }
            thingData      = thingDataList.ToArray();
            this.bossStage = bossStage;
        }
Пример #13
0
        /// <summary>
        /// dllファイルを事前に読み込むことで、dllからdllの間接的な読み込みを防ぐ。
        /// (SDLのsmpeg.dllなどはこれをしないと配置フォルダを変更できないので)
        /// </summary>
        private static YanesdkResult LoadLibrarySafe(string path, string filename)
        {
            YanesdkResult result;

            if (!System.Platform.IsWindows)
            {
                // linuxの場合どうやっていいのかは知らん(`ω´)
                // 必要があるならなんとかしてくれ(´ω`)

                result = YanesdkResult.HappenSomeError;
            }
            else
            {
                string dllPathName = FileSys.ConcatPath(path, filename);

                // いったんCurrent Directoryを変更しないと
                // smpeg.dllのようにDllMainでおかしなことをしているdllは読み込めない。

                // dllは実行ファイル相対で配置されると仮定できる。

                // CurrentDirectoryを一時的に変更する
                {
                    using (CurrentDirectoryHelper helper = new CurrentDirectoryHelper(DllManager.DirectoryPolicy))
                    {
                        // そのdllファイルが存在するのか事前に調べておく。
                        if (FileSys.IsExist(dllPathName))
                        {
                            IntPtr handle = LoadLibrary_(dllPathName);
                            if (handle == IntPtr.Zero)
                            {
                                // Console.WriteLine("dllの読み込みに失敗 : " + dllFileName );
                                //	Debug.Fail(file + " の読み込みに失敗: " +
                                //		(new global::System.ComponentModel.Win32Exception()).Message);
                                result = YanesdkResult.HappenSomeError;                                 // なんか致命的なエラー(´ω`)
                            }
                            else
                            {
                                result = YanesdkResult.NoError;
                            }
                        }
                        else
                        {
                            result = YanesdkResult.FileNotFound;
                        }
                    }
                }
            }
            return(result);
        }
Пример #14
0
        private static void SetupFileWatcher(string configFileName)
        {
            ConfigFileSystemWatcher?.Dispose();

            if (!FileSys.File.Exists(configFileName))
            {
                return;
            }

            ConfigFileSystemWatcher                     = FileSys.CreateFileSystemWatcher(FileSys.Path.GetDirectoryName(configFileName));
            ConfigFileSystemWatcher.Filter              = FileSys.Path.GetFileName(configFileName);
            ConfigFileSystemWatcher.NotifyFilter        = NotifyFilters.LastWrite;
            ConfigFileSystemWatcher.Changed            += (_, _) => ConfigFileSystemWatcherOnChanged(configFileName);
            ConfigFileSystemWatcher.EnableRaisingEvents = true;
        }
Пример #15
0
Файл: Font.cs Проект: sinshu/dtf
        /// <summary>フォントをオープンする。</summary>
        /// <remarks>
        /// <para>
        ///	指定するのは、フォント名。
        ///	indexは、ttc(true type collection=ttfが複数入ったフォントファイル)の
        ///	ときに、何番目のものかを指定する。0番から始まる番号。
        ///	</para>
        /// <para>
        ///	Windowsならフォルダは決まっているので、カレントとパスの通っている
        ///	ところに無ければ、そこから取得する。
        ///	</para>
        /// <para>
        ///	Linuxのほうは、カレント、あとパスの通っているところから取得する。
        ///	</para>
        /// </remarks>
        /// <example>
        ///		例)
        ///		Windowsでは、
        ///		<list type="">
        ///			msgothic.ttc : MSゴシック
        ///			msmincho.ttc : MS明朝
        ///		</list>
        ///		<para>
        ///		Linuxの場合、日本語フォントを用いる場合は、
        ///		GT書体 (東京大学多国語処理研究会)
        ///		http://www.l.u-tokyo.ac.jp/GT/
        ///		などから持ってきて、msgothic.ttcやmsmincho.ttcとリネームして
        ///		カレントフォルダに配置しておくようにしてください。</para>
        ///
        ///		<para>
        ///		フォントフォルダの検索に用いているAPIは、
        ///		win95の場合はIE4.0以降をインストールしてないとダメ
        ///		win98以降は使える。
        ///		</para>
        /// </example>
        public YanesdkResult Load(string fontname, int fontsize, int index)
        {
            Release();

            YanesdkResult hr = Load(FileSys.ReadRW(fontname), fontsize, index);

            if (hr != YanesdkResult.NoError)
            {
                //	カレントにないので、SHGetSpecialFolderPath関数を使って
                //	フォントディレクトリを取得して頑張ってみる。

                string fontpath;
                switch (System.Platform.PlatformID)
                {
                case Yanesdk.System.PlatformID.Windows:
                    fontpath = FileSys.ConcatPath(Environment.SystemDirectory, @"..\fonts");
                    break;

                case Yanesdk.System.PlatformID.Linux:
                    fontpath = "/usr/share/fonts/ja/TrueType/";
                    break;

                case Yanesdk.System.PlatformID.MacOS:
                    fontpath = "/System/Library/Fonts/";
                    break;

                default:
                    throw null;
                }

                hr = Load(FileSys.ReadRW(FileSys.MakeFullName(fontpath, fontname)), fontsize, index);
            }

            if (hr == YanesdkResult.NoError)
            {
                fileName = fontname;

                // もし、ローダー以外からファイルを単に読み込んだだけならば、Reconstructableにしておく。
                if (constructInfo == null)
                {
                    constructInfo = new FontConstructAdaptor(fontname, fontsize, index);
                }
            }

            return(hr);
        }
Пример #16
0
        protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string    newsID = GV.DataKeys[e.RowIndex].Value.ToString();
            SQLHelper db     = new SQLHelper();

            //删除图片
            db.sql = "SELECT pic FROM " + com.tablePrefix + "News WHERE NewsID=" + newsID;
            DataTable dt = db.Get_DataTable();

            if (dt.Rows.Count > 0)
            {
                string pic = dt.Rows[0]["pic"].ToString();
                FileSys.delFile(pic);
            }
            db.sql = "DELETE News WHERE NewsID=" + newsID;
            db.ExecSql();
            bindGv();
            alert.Show(Page, "删除成功");
            return;
        }
Пример #17
0
        /// <summary>
        /// サーフェースへの画像読み込みメソッド。
        /// </summary>
        /// <param name="filename"></param>
        /// <returns>読み込み失敗のときは非0が返る。</returns>
        /// <remarks>
        /// bmp画像,png画像を読み込みサポート。
        /// </remarks>
        public YanesdkResult Load(string filename)
        {
            RWopsH = FileSys.ReadRW(filename);
            if (RWopsH.Handle != IntPtr.Zero)
            {
                surface = SDL.IMG_Load_RW(RWopsH.Handle, 0);
                if (surface != IntPtr.Zero)
                {
                    //	// この時点でsurfaceのαチャンネルの有無を判定して、メンバalphaに反映させる必要あり。
                    //	alpha = getAlpha(surface);
                    // →α channelの判定は動的に行なうように変更する

                    fileName = filename;

                    CacheSystem.OnResourceChanged(this);
                    return(YanesdkResult.NoError);
                }
                return(YanesdkResult.FileReadError);
            }
            else
            {
                return(YanesdkResult.FileNotFound);
            }
        }
Пример #18
0
        /// <summary>
        /// 定義ファイルの読み込み。
        ///
        /// ここで生成したCachedObjectLoaderのDisposeを呼び出さないこと。
        /// (同時に同じ定義ファイルをLoadDefFileしているCachedObjectLoaderのインスタンスと
        /// 同一インスタンスなので、そちら側で困ったことになる)
        /// </summary>
        /// <param name="defFile"></param>
        /// <returns></returns>
        public T LoadDefFile(string defFile)
        {
            // 念のため、一意な名前にしておく。
            // ex. "./def.txt"と"def.txt"が別のファイル名扱いされると
            // Loaderが別になってしまうので。
            string defFileName = FileSys.MakeFullName("", defFile);

            if (maps.ContainsKey(defFileName))
            {
                return(maps[defFileName]);
            }

            T loader = new T();

            loader.Factory = this.Factory;

            OnLoadDefFile(loader);

            loader.IsDefRelativePath = this.isDefRelativePath;
            loader.LoadDefFile(defFile);             // このresultがどうなってようがそれは知らん

            maps.Add(defFileName, loader);
            return(loader);
        }
Пример #19
0
    public HashSet <string> GetDiff(FileSys other)
    {
        HashSet <string> diff = new HashSet <string>();

        foreach (PackageDesc pak in packages.Values)
        {
            PackageDesc pak2;
            if (!other.packages.TryGetValue(pak.name, out pak2) || pak.files.Count != pak2.files.Count)
            {
                diff.Add(pak.name);
                continue;
            }
            foreach (FileDesc file in pak.files.Values)
            {
                FileDesc file2;
                if (!pak2.files.TryGetValue(file.name, out file2) || file.crc != file2.crc)
                {
                    diff.Add(pak.name);
                    break;
                }
            }
        }
        return(diff);
    }
Пример #20
0
        public static void init(MCCSAPI api)
        {
            Mapi             = api;
            TimerTick        = new System.Timers.Timer();
            RunPath          = FileSys.GetPath();
            BakcupPath       = RunPath + BakcupPath;        //备份后存档存放的文件夹的绝对路径
            Profile.HomeDire = BakcupPath;
            GetGameMap();
            CheckDeploy();                                  //检查配置文件是否存在,不存在则打开窗口进行配置

            //TimerTick.Interval = 1000 * 1 * 10;           //1H执行一次 第一次执行就在这个时间后 单位ms
            TimerTick.Elapsed += new System.Timers.ElapsedEventHandler(OnTick);
            //GetGameMap();
            //监听事件:玩家加入世界
            api.addAfterActListener("onLoadName", e =>
            {
                HavePlayer = true;
                return(true);
            });

            //监听事件:后台指令输出信息
            api.addBeforeActListener("onServerCmdOutput", e =>
            {
                var ex        = (ServerCmdOutputEvent)BaseEvent.getFrom(e);
                string output = ex.output;
                String t_tmp  = DateTime.Now.Ticks.ToString();
                //
                if (PrepareBackup)
                {
                    if (output.IndexOf("Data saved. Files are now ready to be copied") != -1 || output.IndexOf("数据已保存。文件现已可供复制") != -1)
                    {
                        Console.WriteLine("已获取备份文件列表,准备备份");
                        new Thread(() =>
                        {
                            string savepath = string.Format("{0}\\{1}\\", Profile.HomeDire, DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"));
                            //备份
                            int count = BackupDB(output.Split(new char[] { '\n' })[1], Profile.Zip? Temp + @"\" + t_tmp + @"\" : savepath);
                            if (Profile.Zip)
                            {
                                try
                                {
                                    Directory.CreateDirectory(savepath);
                                    ZipFile.CreateFromDirectory(Temp + @"\" + t_tmp + @"\" + MapDirName, savepath + MapDirName + ".zip");
                                }
                                catch (Exception error)
                                {
                                    Console.WriteLine("[BackupMap Error] 执行压缩失败,将备份的文件夹复制到备份目录,错误:{0}", error);
                                    Folder.Copy(Temp + @"\" + t_tmp + @"\" + MapDirName, savepath + @"\");
                                }
                                Directory.Delete(Temp + @"\" + t_tmp, true);
                            }
                            if (count != 0)
                            {
                                if (count == -1)
                                {
                                    Console.WriteLine("因备份失败而终止");
                                    PrepareBackup = false;
                                    SeedCMD(SaveResume);
                                    return;
                                }
                                Console.WriteLine("备份结束有{0}个文件备份失败", count);
                            }
                            else
                            {
                                Console.WriteLine("存档全部复制成功");
                            }


                            //备份之后执行的操作
                            if (Profile.run != null && Profile.run != "0" && File.Exists(Profile.run))
                            {
                                bool hasspace = (savepath + MapDirName).IndexOf(" ") != -1;

                                if (Profile.Zip)
                                {
                                    Process.Start(Profile.run, String.Format("{0} {1}", "zip", hasspace? "\"" + savepath + MapDirName + ".zip\"" : savepath + MapDirName + ".zip"));
                                }
                                else
                                {
                                    Process.Start(Profile.run, String.Format("{0} {1}", "dir", hasspace?"\"" + savepath + MapDirName + "\"" : savepath + MapDirName));
                                }
                            }
                            //Thread.Sleep(1000 * 2);
                            SeedCMD(SaveResume);
                            PrepareBackup = false;
                            //告诉插件 存档存储已恢复 可以再次备份
                        }).Start();

                        return(false);                                       //禁止在控制面板上显示这个回显
                    }
                    else
                    {
                        // TODO:当出现还没有准备完成的时候执行
                    }
                }

                return(true);
            });

            api.addBeforeActListener("onServerCmd", e =>
            {
                var ex = (ServerCmdEvent)BaseEvent.getFrom(e);
                if (ex.cmd.ToLower() == "backupmap")
                {
                    if (PrepareBackup)
                    {
                        Console.WriteLine("上次备份尚未结束");
                    }
                    else
                    {
                        StartBackup();  //手动备份
                    }
                    return(false);
                }
                return(true);
            });
        }
Пример #21
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            lbid = lbList.SelectedValue;
            string id          = hID.Value;
            string title       = pg.GetSafeString(txtTitle.Text);
            string oldPic      = hPic.Value;
            string newPic      = hPic_new.Value;
            string oldSmallPic = hSmallPic.Value;
            //string newsBody = pg.GetSafeString(tbxBody.Text).Replace("\"", "''");
            string newsBody = FCKeditor1.Value;
            string pic, picSmall = hSmallPic_new.Value;
            string addtime = pg.GetSafeString(txtAddTime.Text);
            string pid     = hPid.Value;

            pic = oldPic + newPic;
            pic = pic.Replace("||", "|");
            string sql = "";

            if (id.Length > 0)
            {
                if (picSmall == "")
                {
                    //未上传小图
                    picSmall = oldSmallPic;
                }
                else
                {
                    //已上传小图并且原来有图
                    if (picSmall != "" && oldSmallPic != "")
                    {
                        //删除旧图
                        FileSys.delFile(oldSmallPic);
                    }
                }
                DXProd pd = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(id) select pro).First <DXProd>();
                pd.lbid       = Int32.Parse(lbid);
                pd.Name       = title;
                pd.pic        = pic;
                pd.picSmall   = picSmall;
                pd.Body       = newsBody;
                pd.EditorName = Session["AdminName"].ToString();
                pd.EditTime   = DateTime.Now;
                dbContext.SubmitChanges();
                alert.showAndGo("修改成功", "Prod.aspx?lbid=" + lbid);
            }
            else
            {
                try
                {
                    //添加
                    DXProd pd = new DXProd();
                    pd.lbid        = Int32.Parse(lbid);
                    pd.Name        = title;
                    pd.pic         = pic;
                    pd.picSmall    = picSmall;
                    pd.Body        = newsBody;
                    pd.CreateTime  = DateTime.Now;
                    pd.EditTime    = DateTime.Now;
                    pd.CreatorName = Session["AdminName"].ToString();
                    pd.EditorName  = Session["AdminName"].ToString();

                    dbContext.DXProd.InsertOnSubmit(pd);
                    dbContext.SubmitChanges();
                    alert.showAndGo("添加成功", "Prod.aspx?lbid=" + lbid);
                }
                catch (Exception ex)
                {
                    alert.ShowAndBack(Page, "添加失败" + ex.Message);
                }
            }
        }
Пример #22
0
        protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            lbid = hlbid.Value;
            System.Web.UI.WebControls.Button btn = e.CommandSource as System.Web.UI.WebControls.Button;
            if (btn == null)
            {
                return;
            }
            int index = ((System.Web.UI.WebControls.GridViewRow)btn.Parent.Parent).RowIndex;

            DataKey key    = this.GV.DataKeys[index];
            string  NewsID = key.Value.ToString();

            if (e.CommandName == "PicMng")
            {
                Server.Transfer("PhotoManage.aspx?lbid=" + NewsID);
                return;
            }

            GridViewRow gvr = GV.Rows[index];

            if (e.CommandName == "upFile")
            {
                //寻找上传控件
                FileUpload fu = (FileUpload)gvr.FindControl("FileUpload1");
                if (fu != null)
                {
                    if (fu.HasFile)
                    {
                        SQLHelper_ db = new SQLHelper_();
                        //上传图片
                        string pic = UpFile(fu);
                        //删除原图
                        db.sql = "SELECT pic FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID;
                        string pic0 = db.Get_DataTable().Rows[0][0].ToString();
                        if (pic0.Length > 0)
                        {
                            FileSys.delFile(pic0);
                        }

                        //更新数据库
                        db.sql = "UPDATE News SET pic='" + pic + "' WHERE NewsID=" + NewsID;
                        db.ExecSql();

                        bindGv();
                        alert.Show(Page, "图片更新成功");
                    }
                }
            }
            if (e.CommandName == "Save")
            {
                //查找 title控件
                TextBox txtTitle = null;
                try
                {
                    txtTitle = this.GV.Rows[index].Cells[1].Controls[0] as TextBox;
                }
                catch
                {
                    alert.Show(Page, "未找到图片集名称控件");
                    return;
                }
                TextBox txtEditTime = null;
                try
                {
                    txtEditTime = this.GV.Rows[index].Cells[2].Controls[0] as TextBox;
                }
                catch
                {
                    alert.Show(Page, "未找到编辑日期控件");
                    return;
                }



                FileUpload fu = gvr.Cells[4].FindControl("FileUpload1") as FileUpload;

                string title    = pg.GetSafeString(txtTitle.Text.Trim());
                string EditTime = pg.GetSafeString(txtEditTime.Text.Trim());
                if (title == "")
                {
                    alert.Show(Page, "请填写图片集名称");
                    return;
                }
                if (EditTime == "")
                {
                    EditTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                }
                string     pic = UpFile(fu);
                SQLHelper_ db  = new SQLHelper_();
                if (NewsID.Length > 0)
                {
                    if (pic != "")
                    {
                        //更新
                        db.sql = "UPDATE News SET title='" + title + "',pic='" + pic + "',editTime='" + EditTime + "' WHERE NewsID=" + NewsID;
                    }
                    else
                    {
                        //更新
                        db.sql = "UPDATE News SET title='" + title + "',editTime='" + EditTime + "' WHERE NewsID=" + NewsID;
                    }
                    if (db.ExecSql() != "1")
                    {
                        alert.Show(Page, "保存失败");
                    }
                    else
                    {
                        GV.EditIndex = -1;
                        bindGv();
                    }
                }
                else
                {
                    //添加
                    NewsID = clsNews.MaxNewsid();
                    db.sql = "INSERT INTO News(lbid,NewsID,title,pic,EditTime,AddTime) VALUES(" + lbid + "," + NewsID + ",'" + title + "','" + pic + "','" + EditTime + "',getdate())";
                    if (db.ExecSql() != "1")
                    {
                        alert.Show(Page, "添加失败");
                    }
                    else
                    {
                        GV.EditIndex = -1;
                        bindGv();
                    }
                }
            }
        }
Пример #23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            com.adminLogin();

            if (!IsPostBack)
            {
                string id = pg.request("id");
                NewsID = id;
                pid    = pg.request("pid");
                if (pid.Length > 0)
                {
                    pname         = clsLB.getLbname(pid);
                    lblPname.Text = pname;
                    hPid.Value    = pid;
                }


                string act = pg.request("act");
                if (act == "delpic")
                {
                    //由前台的jquery异步调用
                    string imgsrc = pg.request("imgsrc");
                    try
                    {
                        DXProd pd = (from pro in dbContext.DXProd where pro.Id == Int32.Parse(id) select pro).First <DXProd>();
                        pd.pics = pd.pics.Replace(imgsrc, "");
                        pd.pics = pd.pics.Replace("||", "|");
                        dbContext.SubmitChanges();
                        FileSys.delFile(imgsrc);
                        Response.Write("ok");
                    }
                    catch (Exception ex)
                    {
                        Response.Write("ERROR: " + ex.Message);
                    }

                    Response.End();
                }

                if (id != "")
                {
                    pageInit();
                }
                else
                {
                    lbid = pg.request("lbid");
                    if (lbid == "")
                    {
                        lbid = "0";
                    }
                    lbname = clsLB.getLbname(lbid);
                    pid    = clsLB.getPid(lbid);
                    bindLbList(Int32.Parse(pid));

                    txtAddTime.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                    btnAdd.Text     = "添加";
                    lblOper.Text    = "添加" + lbname;
                }
                //txtStar.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}");
                //txtStudentCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}");
                //txtStudentTotalCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}");
            }
        }
Пример #24
0
        protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            productid = hlbid.Value;
            System.Web.UI.WebControls.Button btn = e.CommandSource as System.Web.UI.WebControls.Button;
            if (btn == null)
            {
                return;
            }
            int index = ((System.Web.UI.WebControls.GridViewRow)btn.Parent.Parent).RowIndex;

            DataKey key    = this.GV.DataKeys[index];
            string  NewsID = key.Value.ToString();

            GridViewRow gvr = GV.Rows[index];


            #region 单击上传图片按钮
            if (e.CommandName == "upFile")
            {
                //寻找上传控件
                FileUpload fu  = (FileUpload)gvr.FindControl("FileUpload1");//原图
                string     pic = "";
                //上传图片
                pic = UpFile(fu);
                string picSmall = "";
                if (pic != "")
                {
                    picSmall = pic.ToLower().Replace(".jpg", "_s.jpg");
                    //ThumNail.MakeThumNail(pic, picSmall, 127, 127, "HW");
                    SQLHelper db = new SQLHelper();

                    //删除原图
                    db.sql = "SELECT pic,picSmall FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID;
                    DataTable dtp = db.Get_DataTable();
                    if (dtp.Rows.Count > 0)
                    {
                        string pic0 = dtp.Rows[0][0].ToString();
                        string pic1 = dtp.Rows[0][1].ToString();
                        if (pic0.Length > 0)
                        {
                            FileSys.delFile(pic0);
                        }
                        if (pic1.Length > 0)
                        {
                            FileSys.delFile(pic1);
                        }
                    }
                    //更新数据库
                    db.sql = "UPDATE News SET pic='" + pic + "',picSmall='" + picSmall + "' WHERE NewsID=" + NewsID;
                    db.ExecSql();

                    bindGv();
                    alert.Show(Page, "图片更新成功");
                }
            }
            #endregion

            #region 保存
            if (e.CommandName == "Save")
            {
                //查找 title控件
                TextBox txtTitle = null;
                try
                {
                    txtTitle = this.GV.Rows[index].Cells[1].Controls[0] as TextBox;
                }
                catch
                {
                    alert.ShowAndBack(Page, "未找到标题控件");
                    return;
                }
                string colorid = "-1";

                try
                {
                    DropDownList ddlColor = (DropDownList)GV.Rows[index].FindControl("ddlColor");
                    colorid = ddlColor.SelectedValue;
                }
                catch (Exception)
                {
                    alert.ShowAndBack(Page, "未找到颜色控件");
                    return;
                }

                string imgTypeid = "";
                try
                {
                    DropDownList ddImglType = (DropDownList)GV.Rows[index].FindControl("ddlpro_imgTypeid");
                    imgTypeid = ddImglType.SelectedValue;
                }
                catch (Exception)
                {
                    alert.ShowAndBack(Page, "未找到图片类型控件");
                    return;
                }
                FileUpload fu = gvr.Cells[5].FindControl("FileUpload1") as FileUpload;

                string title = pg.GetSafeString(txtTitle.Text.Trim());
                if (title == "")
                {
                    alert.ShowAndBack(Page, "请填写标题");
                    return;
                }

                TextBox tbxOrder = null;
                try
                {
                    tbxOrder = this.GV.Rows[index].Cells[6].Controls[0] as TextBox;
                }
                catch
                {
                    alert.ShowAndBack(Page, "未找到排序文本框控件");
                    return;
                }
                string orderid = pg.GetSafeString(tbxOrder.Text.Trim());
                if (orderid == "")
                {
                    orderid = "0";
                }

                string pic      = UpFile(fu);
                string picSmall = "";
                if (pic != "")
                {
                    picSmall = pic.ToLower().Replace(".jpg", "_s.jpg");
                }
                SQLHelper db = new SQLHelper();

                if (NewsID.Length > 0)
                {
                    //取出旧图
                    string oldPic = "", oldPicSmall = "";
                    db.sql = "SELECT pic,picSmall FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID;
                    DataTable dt = db.Get_DataTable();
                    if (dt.Rows.Count > 0)
                    {
                        oldPic      = dt.Rows[0]["pic"].ToString();
                        oldPicSmall = dt.Rows[0]["picSmall"].ToString();
                    }
                    //更新
                    string sql = "UPDATE News SET title='" + title + "',ColorId=" + colorid + ",pro_imgTypeid=" + imgTypeid + ",editTime=getdate(),OrderId=" + orderid;
                    if (pic.Length > 0)
                    {
                        sql += " ,pic='" + pic + "'";
                        FileSys.delFile(oldPic);
                    }
                    if (picSmall.Length > 0)
                    {
                        sql += " ,picSmall='" + picSmall + "'";
                        FileSys.delFile(oldPicSmall);
                    }
                    sql   += " WHERE NewsID=" + NewsID;
                    db.sql = sql;
                    if (db.ExecSql() != "1")
                    {
                        alert.Show(Page, "保存失败");
                    }
                    else
                    {
                        GV.EditIndex = -1;
                        bindGv();
                    }
                }
                else
                {
                    //添加
                    NewsID = clsNews.MaxNewsid();

                    db.sql = "INSERT INTO News(ParentNewsID,NewsID,title,ColorId,pro_imgTypeid,pic,picSmall,EditTime,AddTime,OrderId) VALUES(" + productid + "," + NewsID + ",'" + title + "'," + colorid + "," + imgTypeid + ",'" + pic + "','" + picSmall + "',getdate(),getdate()," + orderid + ")";
                    if (db.ExecSql() != "1")
                    {
                        Response.Write("添加失败,sql=" + db.sql);
                        //alert.Show(Page, "添加失败");
                        Response.End();
                    }
                    else
                    {
                        GV.EditIndex = -1;
                        bindGv();
                    }
                }
            }
            #endregion
        }
Пример #25
0
        /// <summary>
        /// 指定したファイルから画像を読み込み、その
        /// System.Drawing.Bitmap を返す。
        ///
        /// 画像の読み込み時には、System.FileSysを
        /// 利用するので、このファイルシステムにadd onされた
        /// アーカイバ等のなかのファイルであっても読める。
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        static public Bitmap LoadToBitmap(string filename)
        {
            try
            {
                // 実在するなら、そのまま読み込めば良い
                string realfile = FileSys.IsRealExist(filename);
                if (realfile != null)
                {
                    return(new Bitmap(realfile));
                }

                // memory stream経由で読み込むように修正

                byte[] data = FileSys.Read(filename);
                if (data == null)
                {
                    return(null);
                }

                using (MemoryStream stream = new MemoryStream(data))
                {
                    return(new Bitmap(stream));
                }
            }
            catch { }
            return(null);

            /*
             * Surface surface = new Surface();
             * if (surface.Load(filename) != YanesdkResult.NoError)
             *      return null;
             *
             * // Bitmap.FromHbitmap(surface.HBitmap);のほうがいいか?
             *
             * int w = surface.Width;
             * int h = surface.Height;
             *
             * Bitmap bitmap = new Bitmap(w,h);
             * BitmapData bmpdata;
             * if (surface.CheckRGB888())
             * {
             *      bmpdata = bitmap.LockBits(new Rectangle(0, 0, w, h),
             *              ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
             *
             *      // 画像コピー
             *      unsafe
             *      {
             *              // 最悪なのことにalignされている(´ω`)
             *
             *              byte* dst = (byte*)bmpdata.Scan0;
             *              int dst_pitch = bmpdata.Stride;
             *              byte* src = (byte*)surface.Pixels;
             *              int src_pitch = surface.Pitch;
             *
             *              for (int y = 0; y < h; ++y)
             *              {
             *                      for (int i = 0; i < w * 3; i += 3)
             *                      {
             *                              // しかもR,G,B逆かよ!(`ω´)
             *                              dst[i + 0] = src[i + 2];
             *                              dst[i + 1] = src[i + 1];
             *                              dst[i + 2] = src[i + 0];
             *                      }
             *                      src += src_pitch;
             *                      dst += dst_pitch;
             *              }
             *      }
             * }
             * else
             * {
             *      bmpdata = bitmap.LockBits(new Rectangle(0, 0, w, h),
             *              ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
             *
             *      // 画像コピー
             *      unsafe
             *      {
             *              // 最悪なのことにalignされている(´ω`)
             *
             *              byte* dst = (byte*)bmpdata.Scan0;
             *              int dst_pitch = bmpdata.Stride;
             *              byte* src = (byte*)surface.Pixels;
             *              int src_pitch = surface.Pitch;
             *
             *              for (int y = 0; y < h; ++y)
             *              {
             *                      for (int i = 0; i < w * 4; i += 4)
             *                      {
             *                              // しかもR,G,B逆かよ!(`ω´)
             *                              dst[i + 0] = src[i + 2];
             *                              dst[i + 1] = src[i + 1];
             *                              dst[i + 2] = src[i + 0];
             *                              dst[i + 3] = src[i + 3];
             *                      }
             *                      src += src_pitch;
             *                      dst += dst_pitch;
             *              }
             *      }
             * }
             *
             * bitmap.UnlockBits(bmpdata);
             *
             * return bitmap;
             */
        }
Пример #26
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            lbid = lbList.SelectedValue;
            string id = hID.Value;
            string title = pg.GetSafeString(txtTitle.Text);
            string bianhao = tbxBianhao.Text.Trim();
            string mianliao = tbxMianliao.Text.Trim();
            string oldPic = hPic.Value;
            string newPic = hPic_new.Value;
            string oldSmallPic = hSmallPic.Value;
            string newsBody = pg.GetSafeString(tbxBody.Text).Replace("\"", "''");
            string size = pg.GetSafeString(tbxSize.Text).Replace("\"", "''");
            string pic, picSmall = hSmallPic_new.Value;
            string addtime = pg.GetSafeString(txtAddTime.Text);
            string pid     = hPid.Value;
            string func    = ",";

            foreach (ListItem li in functionList.Items)
            {
                if (li.Selected == true)
                {
                    func += "," + li.Value;
                }
            }
            if (func != ",")
            {
                func = func.Replace(",,", "");
            }
            pic = oldPic + newPic;
            pic = pic.Replace("||", "|");
            string sql = "";

            if (id.Length > 0)
            {
                if (picSmall == "")
                {
                    //未上传小图
                    picSmall = oldSmallPic;
                }
                else
                {
                    //已上传小图并且原来有图
                    if (picSmall != "" && oldSmallPic != "")
                    {
                        //删除旧图
                        FileSys.delFile(oldSmallPic);
                    }
                }
                //修改
                sql = "UPDATE News SET lbid=" + lbid + ", Title='" + title + "',pro_mianliao='" + mianliao + "',pro_bianhao='" + bianhao + "',picSmall='" + picSmall + "',AddTime='" + addtime + "',Description='" + size + "',NewsBody='" + newsBody + "',Editor='" + Session["AdminName"].ToString() + "',EditTime=getdate(),pro_function='" + func + "' WHERE NewsID=" + id;
                SQLHelper db = new SQLHelper();
                db.sql = sql;
                if (db.ExecSql() == "1")
                {
                    //删除旧文件
                    //if (picSmall != oldPic)
                    //{
                    //    FileSys.delFile(oldPic);
                    //}

                    alert.showAndGo("修改成功", "Prod.aspx?pid=" + pid);
                }
                else
                {
                    //alert.ShowAndBack(Page, "修改失败");
                    Response.Write(sql);
                    Response.End();
                }
            }
            else
            {
                //添加
                string newsid = clsNews.MaxNewsid();
                sql = "INSERT INTO News(NewsID,lbid,Description,Title,picSmall,pro_bianhao,pro_mianliao,AddTime,pro_function,NewsBody,Creator) VALUES(" + newsid + "," + lbid + ",'" + size + "','" + title + "','" + picSmall + "','" + bianhao + "','" + mianliao + "','" + addtime + "','" + func + "','" + newsBody + "','" + Session["AdminName"].ToString() + "')";
                SQLHelper db = new SQLHelper();
                db.sql = sql;
                string result = db.ExecSql();
                if (result == "1")
                {
                    alert.showAndGo("添加成功", "Prod.aspx?pid=" + pid);
                }
                else
                {
                    //Response.Write(sql);
                    alert.ShowAndBack(Page, "添加失败" + result);
                }
            }
        }
Пример #27
0
        protected void Page_Load(object sender, EventArgs e)
        {
            com.adminLogin();

            if (!IsPostBack)
            {
                string NewsID = pg.request("id");
                pid           = pg.request("pid");
                pname         = clsLB.getLbname(pid);
                lblPname.Text = pname;
                hPid.Value    = pid;
                bindLbList();
                bindFunctionList();
                if (NewsID != "")
                {
                    string act = pg.request("act");
                    if (act == "delpic")
                    {
                        //由前台的jquery异步调用
                        string    imgsrc = pg.request("imgsrc");
                        SQLHelper db     = new SQLHelper();
                        db.sql = "UPDATE News SET pic = replace(pic,'" + imgsrc + "','') WHERE NewsID=" + NewsID;
                        db.ExecSql();
                        db.sql = "UPDATE News SET pic = replace(pic,'||','|') WHERE NewsID=" + NewsID;
                        db.ExecSql();
                        FileSys.delFile(imgsrc);
                        Response.Write("ok");
                        Response.End();
                    }
                    else
                    {
                        string sql = "SELECT * FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID;
                        try
                        {
                            SQLHelper db = new SQLHelper();
                            db.sql = sql;
                            DataTable dt = db.Get_DataTable();
                            if (dt.Rows.Count > 0)
                            {
                                string title    = dt.Rows[0]["title"].ToString();
                                string bianhao  = dt.Rows[0]["pro_bianhao"].ToString();
                                string mianliao = dt.Rows[0]["pro_mianliao"].ToString();
                                string newsBody = dt.Rows[0]["NewsBody"].ToString();
                                string desc     = dt.Rows[0]["Description"].ToString();
                                string pic      = dt.Rows[0]["pic"].ToString();
                                string addTime  = dt.Rows[0]["addTime"].ToString();
                                string picSmall = dt.Rows[0]["picSmall"].ToString();
                                if (addTime.Length > 0)
                                {
                                    addTime = Convert.ToDateTime(addTime).ToString("yyyy-MM-dd hh:mm:ss");
                                }
                                lbid = dt.Rows[0]["lbid"].ToString();

                                lbList.SelectedValue = lbid;
                                //lbname = clsLB.getLbname(lbid);
                                hID.Value        = NewsID;
                                hPic.Value       = pic;
                                hSmallPic.Value  = picSmall;
                                txtTitle.Text    = title;
                                tbxBianhao.Text  = bianhao;
                                tbxMianliao.Text = mianliao;
                                txtAddTime.Text  = addTime;
                                tbxBody.Text     = newsBody;
                                tbxSize.Text     = desc;
                                string   func    = dt.Rows[0]["pro_function"].ToString();
                                string[] funcArr = func.Split(',');
                                for (int i = 0; i < functionList.Items.Count; i++)
                                {
                                    foreach (string fun in funcArr)
                                    {
                                        if (functionList.Items[i].Value == fun)
                                        {
                                            functionList.Items[i].Selected = true;
                                        }
                                    }
                                }

                                btnAdd.Text  = "修改并保存";
                                lblOper.Text = "修改" + lbname;
                            }
                        }
                        catch (Exception ex)
                        {
                            Response.Write(ex.Message + "<br>" + sql);
                            Response.End();
                        }
                    }
                }
                else
                {
                    txtAddTime.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                    btnAdd.Text     = "添加";
                    lblOper.Text    = "添加" + lbname;
                }
                //txtStar.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}");
                //txtStudentCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}");
                //txtStudentTotalCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}");
            }
        }
Пример #28
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Session["AdminName"] = "admin"; //
            com.adminLogin();

            if (!IsPostBack)
            {
                bindDDlLbid();

                string NewsID = pg.request("id");
                lbid = pg.request("lbid");
                if (lbid == "")
                {
                    lbid = "2";            //企业新闻
                }
                ddlLbid.SelectedValue = lbid;
                if (NewsID != "")
                {
                    string act = pg.request("act");
                    if (act == "delpic")
                    {
                        //由前台的jquery异步调用
                        string     imgsrc = pg.request("imgsrc");
                        SQLHelper_ db     = new SQLHelper_();
                        db.sql = "UPDATE News SET pic = replace(pic,'" + imgsrc + "','') WHERE NewsID=" + NewsID;
                        db.ExecSql();
                        db.sql = "UPDATE News SET pic = replace(pic,'||','|') WHERE NewsID=" + NewsID;
                        db.ExecSql();
                        FileSys.delFile(imgsrc);
                        Response.Write("ok");
                        Response.End();
                    }
                    else
                    {
                        string sql = "SELECT * FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID;
                        try
                        {
                            SQLHelper_ db = new SQLHelper_();
                            db.sql = sql;
                            DataTable dt = db.Get_DataTable();
                            if (dt.Rows.Count > 0)
                            {
                                string title    = dt.Rows[0]["title"].ToString();
                                string newsBody = dt.Rows[0]["NewsBody"].ToString();
                                string pic      = dt.Rows[0]["pic"].ToString();
                                string addTime  = dt.Rows[0]["addTime"].ToString();
                                string picSmall = dt.Rows[0]["picSmall"].ToString();
                                string desc     = dt.Rows[0]["Description"].ToString();
                                string video    = dt.Rows[0]["pic"].ToString();


                                if (addTime.Length > 0)
                                {
                                    addTime = Convert.ToDateTime(addTime).ToString("yyyy-MM-dd hh:mm:ss");
                                }
                                lbid = dt.Rows[0]["lbid"].ToString();
                                ddlLbid.SelectedValue = lbid;
                                lbname    = clsLB.getLbname(lbid);
                                hID.Value = NewsID;
                                //hPic.Value = pic;
                                hSmallPic.Value  = picSmall;
                                txtTitle.Text    = title;
                                txtAddTime.Text  = addTime;
                                FCKeditor1.Value = newsBody;
                                FCKeditor2.Value = desc;
                                FCKeditor3.Value = video;
                                btnAdd.Text      = "修改并保存";
                                lblOper.Text     = "修改" + lbname;
                            }
                        }
                        catch (Exception ex)
                        {
                            Response.Write(ex.Message + "<br>" + sql);
                            Response.End();
                        }
                    }
                }
                else
                {
                    lbname          = clsLB.getLbname(lbid);
                    txtAddTime.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                    btnAdd.Text     = "添加";
                    lblOper.Text    = "添加" + lbname;
                }
                //txtStar.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}");
                //txtStudentCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}");
                //txtStudentTotalCount.Attributes.Add("onchange", "if(/\\D/.test(this.value)){alert('只能输入数字');this.value=''}");
            }
        }
Пример #29
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string lbid  = ddlLbid.SelectedValue;
            string id    = hID.Value;
            string title = pg.GetSafeString(txtTitle.Text);
            string video = FCKeditor3.Value;
            //string oldPic = hPic.Value;
            //string newPic = hPic_new.Value;
            string oldSmallPic = hSmallPic.Value;
            string newsBody = pg.GetSafeString(FCKeditor1.Value).Replace("\"", "''");
            string desc = pg.GetSafeString(FCKeditor2.Value).Replace("\"", "''");
            string pic = "", picSmall = hSmallPic_new.Value;
            string addtime = pg.GetSafeString(txtAddTime.Text);

            //pic = oldPic + newPic;
            pic = pic.Replace("||", "|");
            string sql = "";

            if (id.Length > 0)
            {
                if (picSmall == "")
                {
                    //未上传小图
                    picSmall = oldSmallPic;
                }
                else
                {
                    //已上传小图并且原来有图
                    if (picSmall != "" && oldSmallPic != "")
                    {
                        //删除旧图
                        FileSys.delFile(oldSmallPic);
                    }
                }
                //修改
                sql = "UPDATE News SET lbid=" + lbid + ",Title='" + title + "',pic = '" + video + "',Description='" + desc + "',AddTime='" + addtime + "',picSmall='" + picSmall + "',NewsBody='" + newsBody + "',Editor='" + Session["AdminName"].ToString() + "',EditTime=getdate() WHERE NewsID=" + id;
                SQLHelper_ db = new SQLHelper_();
                db.sql = sql;
                string result = db.ExecSql();
                if (result == "1")
                {
                    //删除旧文件
                    //if (picSmall != oldPic)
                    //{
                    //    FileSys.delFile(oldPic);
                    //}

                    alert.showAndGo("修改成功", "News.aspx?lbid=" + lbid);
                }
                else
                {
                    //alert.ShowAndBack(Page, "修改失败");
                    Response.Write(result + ",sql=" + sql);
                    Response.End();
                }
            }
            else
            {
                //添加
                string newsid = clsNews.MaxNewsid();
                sql = "INSERT INTO News(NewsID,lbid,Title,pic,Description,AddTime,picSmall,NewsBody,Creator) VALUES(" + newsid + "," + lbid + ",'" + title + "','" + video + "','" + desc + "','" + addtime + "','" + picSmall + "','" + newsBody + "','" + Session["AdminName"].ToString() + "')";
                SQLHelper_ db = new SQLHelper_();
                db.sql = sql;
                string result = db.ExecSql();
                if (result == "1")
                {
                    alert.showAndGo("添加成功", "News.aspx?lbid=" + lbid);
                }
                else
                {
                    //Response.Write(sql);
                    alert.ShowAndBack(Page, "添加失败" + result);
                }
            }
        }
Пример #30
0
        protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            lbid = hlbid.Value;
            System.Web.UI.WebControls.Button btn = e.CommandSource as System.Web.UI.WebControls.Button;
            if (btn == null)
            {
                return;
            }
            int index = ((System.Web.UI.WebControls.GridViewRow)btn.Parent.Parent).RowIndex;

            DataKey key    = this.GV.DataKeys[index];
            string  NewsID = key.Value.ToString();

            GridViewRow gvr = GV.Rows[index];

            if (e.CommandName == "upFile")
            {
                //寻找上传控件
                FileUpload fu_small = (FileUpload)gvr.FindControl("FileUpload2"); //缩略图
                FileUpload fu = (FileUpload)gvr.FindControl("FileUpload1");       //原图
                string     pic = "", picSmall = "";
                //上传图片
                pic = UpFile(fu);
                //上传图片
                //picSmall = UpFile(fu_small);
                if (pic != "")
                {
                    picSmall = pic.ToLower().Replace(".jpg", "_s.jpg");
                    SQLHelper db = new SQLHelper();

                    //删除原图
                    db.sql = "SELECT pic FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID;
                    string pic0 = db.Get_DataTable().Rows[0][0].ToString();
                    if (pic0.Length > 0)
                    {
                        FileSys.delFile(pic0);
                    }

                    //更新数据库
                    db.sql = "UPDATE News SET pic='" + pic + "' WHERE NewsID=" + NewsID;
                    db.ExecSql();

                    bindGv();
                    alert.Show(Page, "图片更新成功");
                }

                if (picSmall != "")
                {
                    SQLHelper db = new SQLHelper();

                    //删除原图
                    db.sql = "SELECT picSmall FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID;
                    string pic0 = db.Get_DataTable().Rows[0][0].ToString();
                    if (pic0.Length > 0)
                    {
                        FileSys.delFile(pic0);
                    }

                    //更新数据库
                    db.sql = "UPDATE News SET picSmall='" + picSmall + "' WHERE NewsID=" + NewsID;
                    db.ExecSql();

                    bindGv();
                    alert.Show(Page, "图片更新成功");
                }
            }
            if (e.CommandName == "Save")
            {
                //查找 title控件
                TextBox txtTitle = null;
                try
                {
                    txtTitle = this.GV.Rows[index].Cells[1].Controls[0] as TextBox;
                }
                catch
                {
                    alert.Show(Page, "未找到标题控件");
                    return;
                }
                TextBox txtEditTime = null;
                try
                {
                    txtEditTime = this.GV.Rows[index].Cells[2].Controls[0] as TextBox;
                }
                catch
                {
                    alert.Show(Page, "未找到标题控件");
                    return;
                }


                //FileUpload fu_small = gvr.Cells[4].FindControl("FileUpload2") as FileUpload;//缩略图
                FileUpload fu = gvr.Cells[4].FindControl("FileUpload1") as FileUpload;

                string title    = pg.GetSafeString(txtTitle.Text.Trim());
                string EditTime = pg.GetSafeString(txtEditTime.Text.Trim());
                if (title == "")
                {
                    alert.Show(Page, "请填写标题");
                    return;
                }
                if (EditTime == "")
                {
                    EditTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                }
                string pic = UpFile(fu), picSmall = "";

                if (pic != "")
                {
                    picSmall = pic.ToLower().Replace(".jpg", "_s.jpg");
                }

                SQLHelper db = new SQLHelper();
                if (NewsID.Length > 0)
                {
                    //取出旧图
                    string oldPic = "", oldPicSmall = "";
                    db.sql = "SELECT pic,picSmall FROM " + com.tablePrefix + "News WHERE NewsID=" + NewsID;
                    DataTable dt = db.Get_DataTable();
                    if (dt.Rows.Count > 0)
                    {
                        oldPic      = dt.Rows[0]["pic"].ToString();
                        oldPicSmall = dt.Rows[0]["picSmall"].ToString();
                    }
                    //更新
                    string sql = "UPDATE News SET title='" + title + "',editTime='" + EditTime + "'";
                    if (pic.Length > 0)
                    {
                        sql += " ,pic='" + pic + "'";
                        FileSys.delFile(oldPic);
                    }
                    if (picSmall.Length > 0)
                    {
                        sql += " ,picSmall='" + picSmall + "'";
                        FileSys.delFile(oldPicSmall);
                    }
                    sql   += " WHERE NewsID=" + NewsID;
                    db.sql = sql;
                    if (db.ExecSql() != "1")
                    {
                        alert.Show(Page, "保存失败");
                    }
                    else
                    {
                        GV.EditIndex = -1;
                        bindGv();
                    }
                }
                else
                {
                    //添加
                    NewsID = clsNews.MaxNewsid();
                    db.sql = "INSERT INTO News(ParentNewsID,NewsID,title,pic,picSmall,EditTime,AddTime) VALUES(" + lbid + "," + NewsID + ",'" + title + "','" + pic + "','" + picSmall + "','" + EditTime + "',getdate())";
                    if (db.ExecSql() != "1")
                    {
                        alert.Show(Page, "添加失败");
                    }
                    else
                    {
                        GV.EditIndex = -1;
                        bindGv();
                    }
                }
            }
        }