コード例 #1
0
        /// <summary>
        /// 数据绑定,集合已知
        /// </summary>
        void BindToTable()
        {
            dgvShow.Rows.Clear();
            //替换数据
            //获取类别 ID
            TwoNewsModel twe = AllModel.News.FirstOrDefault(c => c.NurTypeID == typeID);

            foreach (NewsListModel news in newsList)
            {
                TableModel tm = new TableModel();
                tm.LocalTypeID    = twe.LocalTypeID;
                tm.LocalTypeTitle = twe.LocalTypeTitle;
                tm.NewsLogoImg    = news.thumb;
                tm.NurID          = news.id;
                tm.NurTypeID      = twe.NurTypeID;
                tm.NurTypeTitle   = twe.NurTypeTitle;
                tm.Title          = news.title;

                int index = dgvShow.Rows.Add();
                DataGridViewCheckBoxCell ckCell = new DataGridViewCheckBoxCell();
                ckCell.Tag = tm;
                dgvShow.Rows[index].Cells["Select"] = ckCell;
                //如果已经被添加了该新闻,不可以选择
                if (idList.Contains(tm.NurID))
                {
                    ckCell.ReadOnly = true;
                    dgvShow.Rows[index].DefaultCellStyle = new DataGridViewCellStyle()
                    {
                        ForeColor = Color.FromArgb(152, 152, 152)
                    };
                }
                dgvShow.Rows[index].Cells["NurID"].Value          = tm.NurID;
                dgvShow.Rows[index].Cells["NewsTitle"].Value      = tm.Title;
                dgvShow.Rows[index].Cells["NurTypeTitle"].Value   = tm.NurTypeTitle;
                dgvShow.Rows[index].Cells["NurTypeID"].Value      = tm.NurTypeID;
                dgvShow.Rows[index].Cells["LocalTypeTitle"].Value = tm.LocalTypeTitle;
                dgvShow.Rows[index].Cells["LocalTypeID"].Value    = tm.LocalTypeID;
                //添加浏览按钮
                DataGridViewButtonCell btnCell = new DataGridViewButtonCell();
                btnCell.Tag   = tm;
                btnCell.Value = "كۆرۈش";
                dgvShow.Rows[index].Cells["Broser"]            = btnCell;
                dgvShow.Rows[index].Cells["NewsLogoImg"].Value = tm.NewsLogoImg;
            }
        }
コード例 #2
0
        /// <summary>
        /// 开始按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            //获取所有的ComboBox 控件
            System.Windows.Forms.Control.ControlCollection cc = gbBox.Controls;
            List <ComboBox> cmbs = new List <ComboBox>();

            foreach (var c in cc)
            {
                if (c is ComboBox)
                {
                    cmbs.Add(c as ComboBox);
                }
            }
            //获取所有来自nur的类别,并且有效的
            List <ComboBox> nurs   = cmbs.Where(c => c.Name.StartsWith("cmbnur") && c.SelectedItem is NurNewsTypeModel && (c.SelectedItem as NurNewsTypeModel).TypeID != 0).ToList();
            List <ComboBox> locals = cmbs.Where(c => c.Name.StartsWith("cmblocal") && c.SelectedItem is NewsLocalTypesModel && (c.SelectedItem as NewsLocalTypesModel).TypeID != 0).ToList();

            if (nurs.Count <= 0 || locals.Count <= 0)
            {
                new UgMessageBox("سىز تېخى تۈر تاللىمىدىڭىز، قايتا تاللاڭ", Color.Red).ShowDialog();
                return;
            }
            List <int> ids = new List <int>();

            foreach (var item in nurs)
            {
                NurNewsTypeModel nn = item.SelectedItem as NurNewsTypeModel;
                ids.Add(nn.TypeID);
            }
            if (ids.Count > ids.Distinct().Count())
            {
                //确定有重复
                new UgMessageBox("نۇر تورى تۈر تىزىملىكىدە قايتىلانغان مەزمۇن بار، تەكشۈرۈڭ", Color.Red).ShowDialog();
                return;
            }
            //没有重复,本地类别可以重复

            //筛选所有的没有选择的想
            cmbs = cmbs.Where(c => c.SelectedIndex != 0).ToList();
            //一对一集合
            List <TwoNewsModel> tweList = new List <TwoNewsModel>();

            foreach (var item in nurs)
            {
                //来自 nur.cn
                NurNewsTypeModel nurType = item.SelectedItem as NurNewsTypeModel;
                string           nurName = item.Name;
                string           id      = nurName.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries)[1];
                //来自本地
                ComboBox cm = locals.FirstOrDefault(c => c.Name.Split(new char[] { '_' })[1] == id);
                if (cm != null)
                {
                    //添加到集合中
                    NewsLocalTypesModel localType = cm.SelectedItem as NewsLocalTypesModel;
                    TwoNewsModel        tw        = new TwoNewsModel();
                    tw.NurTypeID      = nurType.TypeID;
                    tw.NurTypeTitle   = nurType.Title;
                    tw.LocalTypeID    = localType.TypeID;
                    tw.LocalTypeTitle = localType.TypeTitle;
                    tweList.Add(tw);
                }
            }
            if (tweList.Count <= 0)
            {
                //没有一对一
                new UgMessageBox("سىز تاللىغان تۈرلەر بىر-بىرىگە ماس ئەمەس، تەكشۈرۈڭ ياكى قايتا تاللاڭ", Color.Red).ShowDialog();
                return;
            }

            //完成
            AllModel.News = tweList;
            //判断两者是否相等
            if (AllModel.NurNewsTypeList.Count > tweList.Count)
            {
                //重新写入日记文件
                AllModel.NurNewsTypeList = (from tp in AllModel.NurNewsTypeList
                                            where tweList.Select(c => c.NurTypeID).Contains(tp.TypeID)
                                            select tp).ToList();

                string jss = JsonConvert.SerializeObject(AllModel.NurNewsTypeList);
                File.WriteAllText("log\\nurnewstypes.log", jss);
            }
            //写入到本地
            string js = JsonConvert.SerializeObject(tweList);

            File.WriteAllText("log\\twonewsmodels.log", js);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
コード例 #3
0
        /// <summary>
        /// 开始按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            //获取所有的ComboBox 控件
            System.Windows.Forms.Control.ControlCollection cc = gbBox.Controls;
            List<ComboBox> cmbs = new List<ComboBox>();
            foreach (var c in cc)
            {
                if (c is ComboBox)
                {
                    cmbs.Add(c as ComboBox);
                }
            }
            //获取所有来自nur的类别,并且有效的
            List<ComboBox> nurs = cmbs.Where(c => c.Name.StartsWith("cmbnur") && c.SelectedItem is NurNewsTypeModel && (c.SelectedItem as NurNewsTypeModel).TypeID != 0).ToList();
            List<ComboBox> locals = cmbs.Where(c => c.Name.StartsWith("cmblocal") && c.SelectedItem is NewsLocalTypesModel && (c.SelectedItem as NewsLocalTypesModel).TypeID != 0).ToList();
            if (nurs.Count <= 0 || locals.Count <= 0)
            {
                new UgMessageBox("سىز تېخى تۈر تاللىمىدىڭىز، قايتا تاللاڭ", Color.Red).ShowDialog();
                return;
            }
            List<int> ids = new List<int>();
            foreach (var item in nurs)
            {
                NurNewsTypeModel nn = item.SelectedItem as NurNewsTypeModel;
                ids.Add(nn.TypeID);
            }
            if (ids.Count > ids.Distinct().Count())
            {
                //确定有重复
                new UgMessageBox("نۇر تورى تۈر تىزىملىكىدە قايتىلانغان مەزمۇن بار، تەكشۈرۈڭ", Color.Red).ShowDialog();
                return;
            }
            //没有重复,本地类别可以重复

            //筛选所有的没有选择的想
            cmbs = cmbs.Where(c => c.SelectedIndex != 0).ToList();
            //一对一集合
            List<TwoNewsModel> tweList = new List<TwoNewsModel>();
            foreach (var item in nurs)
            {
                //来自 nur.cn
                NurNewsTypeModel nurType = item.SelectedItem as NurNewsTypeModel;
                string nurName = item.Name;
                string id = nurName.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries)[1];
                //来自本地
                ComboBox cm = locals.FirstOrDefault(c => c.Name.Split(new char[] { '_' })[1] == id);
                if (cm != null)
                {
                    //添加到集合中
                    NewsLocalTypesModel localType = cm.SelectedItem as NewsLocalTypesModel;
                    TwoNewsModel tw = new TwoNewsModel();
                    tw.NurTypeID = nurType.TypeID;
                    tw.NurTypeTitle = nurType.Title;
                    tw.LocalTypeID = localType.TypeID;
                    tw.LocalTypeTitle = localType.TypeTitle;
                    tweList.Add(tw);
                }
            }
            if (tweList.Count <= 0)
            {
                //没有一对一
                new UgMessageBox("سىز تاللىغان تۈرلەر بىر-بىرىگە ماس ئەمەس، تەكشۈرۈڭ ياكى قايتا تاللاڭ", Color.Red).ShowDialog();
                return;
            }

            //完成
            AllModel.News = tweList;
            //判断两者是否相等
            if (AllModel.NurNewsTypeList.Count > tweList.Count)
            {
                //重新写入日记文件
                AllModel.NurNewsTypeList = (from tp in AllModel.NurNewsTypeList
                                           where tweList.Select(c => c.NurTypeID).Contains(tp.TypeID)
                                           select tp).ToList();

                string jss = JsonConvert.SerializeObject(AllModel.NurNewsTypeList);
                File.WriteAllText("log\\nurnewstypes.log", jss);
            }
            //写入到本地
            string js = JsonConvert.SerializeObject(tweList);
            File.WriteAllText("log\\twonewsmodels.log", js);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }