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

📄 form1.cs

📁 专业实例开发
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			this.label2.Location = new System.Drawing.Point(16, 18);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(112, 23);
			this.label2.TabIndex = 0;
			this.label2.Text = "Destination Directory";
			// 
			// imageList1
			// 
			this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// watchDir
			// 
			this.watchDir.EnableRaisingEvents = true;
			this.watchDir.Filter = "*.doc";
			this.watchDir.SynchronizingObject = this;
			this.watchDir.Created += new System.IO.FileSystemEventHandler(this.watchDir_Created);
			// 
			// errMessage
			// 
			this.errMessage.DataMember = null;
			// 
			// eventLog
			// 
			this.eventLog.Log = "Application";
			this.eventLog.Source = "CreativeLearning";
			this.eventLog.SynchronizingObject = this;
			// 
			// eventLog1
			// 
			this.eventLog1.SynchronizingObject = this;
			// 
			// frmCreative
			// 
			this.AcceptButton = this.btnOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.SystemColors.ControlLight;
			this.ClientSize = new System.Drawing.Size(432, 303);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.tabControl1,
																		  this.btnCancel,
																		  this.btnOK});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmCreative";
			this.Opacity = 0.98000001907348633;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Creative Learning";
			this.Load += new System.EventHandler(this.frmCreative_Load);
			this.tabControl1.ResumeLayout(false);
			this.tabSource.ResumeLayout(false);
			this.tabDest.ResumeLayout(false);
			this.groupEventLog.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.watchDir)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.eventLog)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmCreative());
		}

		private void notifyIcon1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
		
		}

		private void frmCreative_Load(object sender, System.EventArgs e)
		{
			txtSource.Text="D:\\Creative\\Source\\";
            txtProcessedFile.Text="D:\\Creative\\Processed\\";
			txtDest.Text="D:\\Creative\\Destination\\";
			optGenerateLog.Checked=true;
		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			if (!Directory.Exists(txtSource.Text))
			{
				errMessage.SetError(txtSource,"Invalid source directory");
				txtSource.Focus();
				tabControl1.SelectedTab=tabSource;
				return;
			}
			else
				errMessage.SetError(txtSource,"");
			if (!Directory.Exists(txtDest.Text))
			{
				errMessage.SetError(txtDest,"Invalid destination directory");
				txtDest.Focus();
				tabControl1.SelectedTab=tabDest;
				return;
			}
			else
				errMessage.SetError(txtDest,"");
			if (!Directory.Exists(txtProcessedFile.Text))
			{
				errMessage.SetError(txtProcessedFile,"Invalid processed file directory");
				txtProcessedFile.Focus();
				tabControl1.SelectedTab=tabSource;
				return;
			}
			else
				errMessage.SetError(txtProcessedFile,"");
			watchDir.Path=txtSource.Text;
			watchDir.EnableRaisingEvents=true;
			icoNotify.Icon=m_Ready;
			icoNotify.Visible=true;
			this.ShowInTaskbar=false;
			this.Hide();
		}

		private void chkDaily_CheckedChanged(object sender, System.EventArgs e)
		{
		
		}

		private void txtSource_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (Directory.Exists(txtSource.Text))
				txtSource.BackColor=Color.White;
			else
				txtSource.BackColor=Color.Pink;
		}

		private void txtProcessedFile_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (Directory.Exists(txtProcessedFile.Text))
				txtProcessedFile.BackColor=Color.White;
			else
				txtProcessedFile.BackColor=Color.Pink;
		}

		private void txtDest_TextChanged(object sender, System.EventArgs e)
		{
		}

		private void menuItem3_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void mnuConfigure_Click(object sender, System.EventArgs e)
		{
			icoNotify.Visible=false;
			this.ShowInTaskbar=true;
			this.Show();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void icoNotify_DoubleClick(object sender, System.EventArgs e)
		{
			icoNotify.Visible=false;
			this.ShowInTaskbar=true;
			this.Show();
		}

		private void watchDir_Created(object sender, System.IO.FileSystemEventArgs e)
		{
			watchDir.EnableRaisingEvents=false;
			icoNotify.Icon=m_Info;
			icoNotify.Text="Processed: "+ e.Name;
			Word.Application wdApp= new Word.ApplicationClass();
			object optional=System.Reflection.Missing.Value;
			XmlTextWriter xmlWrite;
			xmlWrite= new XmlTextWriter(txtDest.Text + "Summary.xml",null);
           
			try
			{
				Word.Document Doc = new Word.DocumentClass();
				object filename=e.FullPath;
			
				Doc=wdApp.Documents.Open(ref filename, ref optional, ref optional,ref optional,ref optional,ref optional,ref optional,ref optional,ref optional,ref optional,ref optional,ref optional);
				Word.Range wdRange;
				wdRange=Doc.Paragraphs.Item(2).Range;
				string strMemo, strAmount;
				int intParacount;
				strMemo=wdRange.Text;
				strMemo=strMemo.Substring(15,4);
				intParacount=Doc.Paragraphs.Count;
				intParacount=intParacount-2;
				wdRange=Doc.Paragraphs.Item(intParacount).Range;
				object count="-1";
				object wdCharacter="1";
				wdRange.MoveEnd(ref wdCharacter,ref count);
				strAmount=wdRange.Text;
				strAmount=strAmount.Substring(23);

				xmlWrite.Formatting=Formatting.Indented;
				xmlWrite.WriteDocType("Sales",null,null,null);
				xmlWrite.WriteComment("Summary of sales at Creative Learning");
				xmlWrite.WriteStartElement("Sales");
				
				xmlWrite.WriteStartElement(Convert.ToString(DateTime.Today));
				
				xmlWrite.WriteElementString("Memo",strMemo);
				xmlWrite.WriteElementString("Amount",strAmount);
				xmlWrite.WriteEndElement();
				xmlWrite.WriteEndElement();
				icoNotify.Icon=m_Ready;
				
			}
			catch (Exception catchException)
			{
				icoNotify.Icon=m_Error;
				icoNotify.Text="Error in " + e.Name;
				if (optGenerateLog.Checked==true)
                    eventLog.WriteEntry(e.Name + ": " + catchException.Message);
			}
			finally
			{
			xmlWrite.Flush();
				xmlWrite.Close();
				wdApp.Quit(ref optional, ref optional, ref optional);
				wdApp=null;
				watchDir.EnableRaisingEvents=true;
			}
			tryagain:
			try
			{
			
				File.Move(e.FullPath,txtProcessedFile.Text+e.Name);
			}
			catch
			{
				goto tryagain;
			}
		}

		private void btnRefresh_Click(object sender, System.EventArgs e)
		{
			lstEvents.Items.Clear();
			eventLog.Log="Application";
			eventLog.MachineName=".";
			foreach (EventLogEntry logEntry in eventLog.Entries)
			{
				if (logEntry.Source=="CreativeLearning")
				{
					lstEvents.Items.Add(logEntry.Message);
				}
			}
		}

		private void btnSummary_Click(object sender, System.EventArgs e)
		{
			StreamReader strRead;
	
			try
			{
				strRead= new StreamReader(txtDest.Text+"Summary.xml");
				MessageBox.Show(strRead.ReadToEnd(),txtDest.Text+"Summary.xml",MessageBoxButtons.OK,MessageBoxIcon.Information);
				strRead.Close();
			}
			catch(Exception exc)
			{
				MessageBox.Show("An error was returned: " + exc.Message + "Please check the destination folder for summary");
			}

			
			
		}

		private void txtDest_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (Directory.Exists(txtDest.Text))
				txtDest.BackColor=Color.White;
			else
				txtDest.BackColor=Color.Pink;
		}

		private void mnuNotify_Popup(object sender, System.EventArgs e)
		{
		
		}

		private void optGenerateLog_CheckedChanged(object sender, System.EventArgs e)
		{
		
		}
	}
}

⌨️ 快捷键说明

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