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

📄 control.cs

📁 电子像册: 采用C#和SQL编写
💻 CS
📖 第 1 页 / 共 4 页
字号:
			this.buttonadd.Image = ((System.Drawing.Image)(resources.GetObject("buttonadd.Image")));
			this.buttonadd.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("buttonadd.ImageAlign")));
			this.buttonadd.ImageIndex = ((int)(resources.GetObject("buttonadd.ImageIndex")));
			this.buttonadd.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("buttonadd.ImeMode")));
			this.buttonadd.Location = ((System.Drawing.Point)(resources.GetObject("buttonadd.Location")));
			this.buttonadd.Name = "buttonadd";
			this.buttonadd.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("buttonadd.RightToLeft")));
			this.buttonadd.Size = ((System.Drawing.Size)(resources.GetObject("buttonadd.Size")));
			this.buttonadd.TabIndex = ((int)(resources.GetObject("buttonadd.TabIndex")));
			this.buttonadd.Text = resources.GetString("buttonadd.Text");
			this.buttonadd.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("buttonadd.TextAlign")));
			this.buttonadd.Visible = ((bool)(resources.GetObject("buttonadd.Visible")));
			this.buttonadd.Click += new System.EventHandler(this.buttonadd_Click);
			// 
			// panel1
			// 
			this.panel1.AccessibleDescription = resources.GetString("panel1.AccessibleDescription");
			this.panel1.AccessibleName = resources.GetString("panel1.AccessibleName");
			this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("panel1.Anchor")));
			this.panel1.AutoScroll = ((bool)(resources.GetObject("panel1.AutoScroll")));
			this.panel1.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("panel1.AutoScrollMargin")));
			this.panel1.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("panel1.AutoScrollMinSize")));
			this.panel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel1.BackgroundImage")));
			this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.panel1.Controls.Add(this.列表);
			this.panel1.Controls.Add(this.pictureBox);
			this.panel1.Controls.Add(this.buttonadd);
			this.panel1.Controls.Add(this.buttondel);
			this.panel1.Controls.Add(this.textName);
			this.panel1.Controls.Add(this.label4);
			this.panel1.Controls.Add(this.textTime);
			this.panel1.Controls.Add(this.textDesc);
			this.panel1.Controls.Add(this.label5);
			this.panel1.Controls.Add(this.btnModify);
			this.panel1.Controls.Add(this.btnUpdate);
			this.panel1.Controls.Add(this.label3);
			this.panel1.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("panel1.Dock")));
			this.panel1.Enabled = ((bool)(resources.GetObject("panel1.Enabled")));
			this.panel1.Font = ((System.Drawing.Font)(resources.GetObject("panel1.Font")));
			this.panel1.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("panel1.ImeMode")));
			this.panel1.Location = ((System.Drawing.Point)(resources.GetObject("panel1.Location")));
			this.panel1.Name = "panel1";
			this.panel1.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("panel1.RightToLeft")));
			this.panel1.Size = ((System.Drawing.Size)(resources.GetObject("panel1.Size")));
			this.panel1.TabIndex = ((int)(resources.GetObject("panel1.TabIndex")));
			this.panel1.Text = resources.GetString("panel1.Text");
			this.panel1.Visible = ((bool)(resources.GetObject("panel1.Visible")));
			// 
			// Form1
			// 
			this.AccessibleDescription = resources.GetString("$this.AccessibleDescription");
			this.AccessibleName = resources.GetString("$this.AccessibleName");
			this.AutoScaleBaseSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScaleBaseSize")));
			this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll")));
			this.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMargin")));
			this.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMinSize")));
			this.BackColor = System.Drawing.Color.Peru;
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize")));
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.lblmessage);
			this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
			this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("$this.ImeMode")));
			this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
			this.MaximizeBox = false;
			this.MaximumSize = ((System.Drawing.Size)(resources.GetObject("$this.MaximumSize")));
			this.MinimumSize = ((System.Drawing.Size)(resources.GetObject("$this.MinimumSize")));
			this.Name = "Form1";
			this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("$this.RightToLeft")));
			this.StartPosition = ((System.Windows.Forms.FormStartPosition)(resources.GetObject("$this.StartPosition")));
			this.Text = resources.GetString("$this.Text");
			this.列表.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			this.tabPage2.ResumeLayout(false);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		/// <summary>
		/// This method queries the database to obtain all album and photos
		/// then inserts the records into the tree  control
		/// </summary>
		private void LoadData()
		{
			//设置所有视图对应的模型
			treeAlbum.SetModel(model);
			pictureBox.SetModel(model);
			listView1.SetModel(model);
			textName.SetModel(model);
			textTime.SetModel(model);
			textDesc.SetModel(model);

			textName.type=TextType.name;
			textTime.type=TextType.time;
			textDesc.type=TextType.desc;

			//向模型中登记观察者
			model.registerObserver(treeAlbum);
			model.registerObserver(pictureBox);
			model.registerObserver(listView1);
			model.registerObserver(textName);
			model.registerObserver(textTime);
			model.registerObserver(textDesc);
		}

		/// <summary>
		/// This method queries the database to obtain all album and photos
		/// then inserts the records into the tree  control
		/// </summary>

		private void treeAlbum_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
				if( true == btnUpdate.Enabled )
				{
					btnUpdate.Enabled = false;
					textName.Enabled = false;
					textTime.Enabled = false;
					textDesc.Enabled = false;
				}

				TreeItem item = (TreeItem)e.Node.Tag;
					
				if( ItemType.Album == item.Type )
				{
					model.select(-1);
				}
				else
					model.select(item.Id);
		}


		//点击修改按钮,通知视图作出反应
		private void btnModify_Click(object sender, System.EventArgs e)
		{
			btnUpdate.Enabled = true;
			textName.Enabled = true;
			textTime.Enabled = true;
			textDesc.Enabled = true;
		}

		//点击更新按钮,通知模型修改数据库,同时通知视图作出反应
		private void btnUpdate_Click(object sender, System.EventArgs e)
		{
			model.update(textName.Text,textTime.Text,textDesc.Text);

			btnUpdate.Enabled = false;
			textName.Enabled = false;
			textTime.Enabled = false;
			textDesc.Enabled = false;
		}

		//点击查找按钮,通知模型对数据库进行操作
		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			int nIndex=comboBox1.SelectedIndex;
			model.search(nIndex,textBox2.Text);
		}

		//在查找的结果中选取一张照片,通知数据库取数据
		private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(listView1.SelectedIndices.Count>0)
			{
				int nindex=listView1.SelectedIndices[0];
				int vv=(int)(listView1.Items[nindex].Tag);
				model.select(vv);
			}
		}

	

		private void buttonadd_Click(object sender, System.EventArgs e)
		{
			if(treeAlbum.SelectedNode!=null)
			{
				TreeItem item = (TreeItem)treeAlbum.SelectedNode.Tag;
				if(item.Type==ItemType.Album)
				{
					if( DialogResult.OK == FileOpenDlg.ShowDialog() )
					{
						//在打开的选择框中选择照片——可以是多选
						foreach( string file in FileOpenDlg.FileNames )
						{
							//通知模型对数据库进行操作
							//像数据库中插入一条记录
							int newid=model.addphoto(file,item.Id);
							//打开当前添加的照片
							model.select(newid);
						}
					}
				}
				else
					MessageBox.Show("请首先选择类别");
			}
			else
				MessageBox.Show("请首先选择类别");
		}

		private void buttondel_Click(object sender, System.EventArgs e)
		{
			//删除照片
			int oldid=model.deletephoto();
			//如果删出的不是列表中的第一张照片,那么显示它的上一张照片
			if(oldid>0)
				model.select((int)model.idList[oldid-1]);
				//如果删出的是列表中的第一张照片,那么显示它的下一张照片
			else if(oldid==0 && model.idList.Count>0)
				model.select((int)model.idList[0]);
		}

	}

}

⌨️ 快捷键说明

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