コード例 #1
0
        public static bool UpdateMenu(MenuInfo mi)
        {
            bool result = false;

            try
            {
                using (SQLiteConnection conn = new SQLiteConnection("data source=" + Program.CONFIG_DB))
                {
                    conn.Open();
                    string sql = "update TB_Menus set Name=@Name,Sort=@Sort where MenuID=@ID";
                    using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
                    {
                        cmd.Parameters.AddWithValue("@ID", mi.ID);
                        cmd.Parameters.AddWithValue("@Name", mi.Name);
                        cmd.Parameters.AddWithValue("@Sort", mi.Sort);
                        cmd.ExecuteNonQuery();
                    }
                    conn.Close();
                }
                result = true;
            }
            catch { }
            return(result);
        }
コード例 #2
0
        public static bool AppendMenu(MenuInfo mi)
        {
            bool result = false;

            try
            {
                using (SQLiteConnection conn = new SQLiteConnection("data source=" + Program.CONFIG_DB))
                {
                    conn.Open();
                    string sql = "insert into TB_Menus(MenuID,Name,Sort) values(@ID,@Name,@Sort)";
                    using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
                    {
                        cmd.Parameters.AddWithValue("@ID", mi.ID);
                        cmd.Parameters.AddWithValue("@Name", mi.Name);
                        cmd.Parameters.AddWithValue("@Sort", mi.Sort);
                        cmd.ExecuteNonQuery();
                    }
                    conn.Close();
                }
                result = true;
            }
            catch { }
            return(result);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: Jaofeng/SaveCopier
        private void ShowGameList(MenuInfo mi)
        {
            panRight.Hide();
            Application.DoEvents();
            labClass.Text = mi.Name;
            panGame.Controls.Clear();
            Application.DoEvents();
            LinkLabel lnk = new LinkLabel();

            lnk.Name     = "lnkGame";
            lnk.Location = new Point(0, -100);
            lnk.Text     = "None";
            panGame.Controls.Add(lnk);
            GameButton      gb  = null;
            List <GameInfo> lgi = Program.Games.FindAll(gi => gi.MenuID.Equals(mi.ID, StringComparison.OrdinalIgnoreCase));

            lgi.Sort((g1, g2) => g1.Sort.CompareTo(g2.Sort));
            foreach (GameInfo gi in lgi)
            {
                gb             = new GameButton();
                gb.Text        = gi.Name;
                gb.Name        = string.Format("gb_{0}", gi.ID.Replace(" ", "_"));
                gb.MouseEnter += new EventHandler(MenuItem_MouseEnter);
                gb.Font        = _MenuFont;
                gb.ForeColor   = _MenuTextColor;
                gb.BackColor   = _MenuBackColor;
                gb.Click      += new EventHandler(GameButton_Click);
                gb.Dock        = DockStyle.Top;
                gb.Height      = _GameItemHeight;
                gb.Tag         = gi.ID;

                #region 處理圖示
                if (!string.IsNullOrEmpty(gi.Icon))
                {
                    string iconPath  = string.Empty;
                    int    iconIndex = 0;
                    if (gi.Icon.IndexOf(',') != -1)
                    {
                        string[] sp = gi.Icon.Split(',');
                        iconPath = sp[0];
                        int.TryParse(sp[1], out iconIndex);
                    }
                    else
                    {
                        iconPath = gi.Icon;
                    }
                    //iconPath = iconPath.Replace("%Game%", gi.Path);
                    if (!Path.IsPathRooted(iconPath))
                    {
                        iconPath = Path.Combine(_IconPath, iconPath);
                    }
                    Image img = null;
                    if (File.Exists(iconPath))
                    {
                        string[] mime = GameInfo.MimeType(iconPath).ToLower().Split('/');

                        switch (mime[0])
                        {
                        case "application":
                        {
                            Icon[] icons = IconHandler.IconsFromFile(iconPath, IconSize.Large);
                            if (icons != null && icons.Length != 0)
                            {
                                if (icons.Length <= iconIndex)
                                {
                                    img = icons[0].ToBitmap();
                                }
                                else
                                {
                                    img = icons[iconIndex].ToBitmap();
                                }
                            }
                            break;
                        }

                        case "image":
                        {
                            switch (mime[1])
                            {
                            case "x-icon":
                            {
                                Size s = Size.Empty;
                                if (_IconAreaWidth > gb.Height)
                                {
                                    s = new Size(gb.Height, gb.Height);
                                }
                                else
                                {
                                    s = new Size(_IconAreaWidth, _IconAreaWidth);
                                }
                                img = new Icon(iconPath, s).ToBitmap();
                                break;
                            }

                            default:
                                img = Image.FromFile(iconPath);
                                break;
                            }
                            break;
                        }
                        }
                    }
                    if (img != null)
                    {
                        gb.IconWidth = _IconAreaWidth;
                        gb.Icon      = img;
                        gb.ShowIcon  = true;
                    }
                }
                #endregion

                #region 處理上/下傳按鍵
                gb.ShowSaveButton = gi.HasSave;
                if (gi.HasSave)
                {
                    gb.UploadButtonText      = "上傳進度";
                    gb.UploadButtonFont      = new Font("新細明體", 9);
                    gb.UploadButtonImage     = global::SaveCopier.Properties.Resources.Previous;
                    gb.UploadButtonEnabled   = !string.IsNullOrEmpty(_LoginedUserID);
                    gb.UploadClick          += new EventHandler(GameButton_UploadClick);
                    gb.DownloadButtonText    = "下載進度";
                    gb.DownloadButtonFont    = new Font("新細明體", 9);
                    gb.DownloadButtonImage   = global::SaveCopier.Properties.Resources.Next;
                    gb.DownloadButtonEnabled = !string.IsNullOrEmpty(_LoginedUserID);
                    gb.DownloadClick        += new EventHandler(GameButton_DownloadClick);
                    gb.SaveButtonWidth       = _SaveButtonWidth;
                }
                #endregion

                panGame.Controls.Add(gb);
                gb.BringToFront();
                Application.DoEvents();
            }
            panRight.Show();
            Application.DoEvents();
            panGame.Focus();
        }