⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmroom.cs

📁 定义社区节点
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using System.Windows.Forms;
using feiyun0112.cnblogs.com.CSDNReader.Model;
using feiyun0112.cnblogs.com.CSDNReader.Functions;

namespace feiyun0112.cnblogs.com.CSDNReader
{
    public partial class frmRoom : Form
    {
        private Room _room;
        public Model.Room Room
        {
            get { return _room; }
            set 
            {
                Room r = value;
                _room =r.Clone() ;
                
                txtName.Text = _room.Name;
                txtURL.Text = _room.URL;
                
                if(_room.IsGroup)
                {
                    chkGroup.Enabled=false ;
                }
                chkGroup.Checked = _room.IsGroup;

                if (_room.GroupID > 0)
                {
                    if (_room.IsGroup)
                    {
                        chkChild.Enabled = false;
                    }
                    else
                    {
                        chkChild.Checked = true;
                        try
                        {
                            cboGroup.SelectedValue = _room.GroupID;
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    chkChild.Checked = false;
                }
            }
        }

        public frmRoom()
        {
            InitializeComponent();

            cboGroup.DataSource= RoomDBFunc.GetGroupRooms();
            cboGroup.DisplayMember="Name";
            cboGroup.ValueMember="ID";

            chkChild.Checked = false;
            chkGroup.Checked = false;

            this.Room = new Room();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!ValidCheck())
            {
                return;
            }


            this.Room.Name = txtName.Text;
            
            this.Room.IsGroup = chkGroup.Checked;
            if (!this.Room.IsGroup)
            {
                this.Room.URL = txtURL.Text;                            
            }
            else
            {                
                this.Room.URL = "";
                this.Room.Topics.Clear();
            }
            if (chkChild.Checked)
            {
                try
                {
                    this.Room.GroupID = int.Parse(cboGroup.SelectedValue.ToString());
                }
                catch
                {
                    this.Room.GroupID = 0;
                }
            }    

            this.DialogResult = DialogResult.OK;
        
        }

        private bool ValidCheck()
        {
            if (txtName.Text.Trim() .Length==0)
            {
                MsgFunc.ShowWarning("名称不能为空");

                return false ;
            }
            if (!chkGroup.Checked)
            {
                if (txtURL.Text.Trim() .Length==0)
                {
                    MsgFunc.ShowWarning("URL不能为空");
                    return false;
                }
            }
            if (chkChild.Checked)
            {
                if (this.Room.ID == int.Parse(cboGroup.SelectedValue.ToString()))
                {
                    MsgFunc.ShowWarning("组选择错误!");
                    return false;
                }

            }

            //////if (!(new RoomDBFunc().CheckURL(txtURL.Text, Room == null ? -1 : Room.ID)))
            //////{
            //////    return false;
            //////}


            //////if (!(new RoomFunc(null).CheckURL(txtURL.Text)))
            //////{
            //////    MsgFunc.ShowWarning("URL不正确");
            //////    return false;
            //////}

            return  true ;
        }

        private void chkGroup_CheckedChanged(object sender, EventArgs e)
        {
            txtURL.Enabled = !chkGroup.Checked;
            
        }

        private void chkChild_CheckedChanged(object sender, EventArgs e)
        {
            cboGroup.Enabled =   chkChild.Checked;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -