WarrentInput.cs
资源名称:VCSDB.rar [点击查看]
上传用户:hjieqiu
上传日期:2013-05-11
资源大小:16494k
文件大小:51k
源码类别:
企业管理
开发平台:
C#
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.SqlClient;
- namespace 财务管理系统
- {
- /// <summary>
- /// WarrentInput 的摘要说明。
- /// </summary>
- public class WarrentInput : System.Windows.Forms.Form
- {
- private DataTable newTable;//保存某一凭证的分录信息
- private DateTime gridMouseDownTime;//保存在某个窗体单元上的鼠标点击时间,以确定是单击还是双击
- private bool enableDoubleClick;//是否允许双击添加分录记录
- private CurrencyManager cmOrders;//数据导航控制
- public static string mID,mName;//保存从科目选择窗体中输入的科目代码和名称
- private System.Windows.Forms.ImageList imageList1;
- private System.Windows.Forms.ToolBar toolBar1;
- private System.Windows.Forms.ToolBarButton tBtnFirst;
- private System.Windows.Forms.ToolBarButton tBtnPre;
- private System.Windows.Forms.ToolBarButton tBtnNext;
- private System.Windows.Forms.ToolBarButton tBtnLast;
- private System.Windows.Forms.ToolBarButton tBtnNew;
- private System.Windows.Forms.ToolBarButton tBtnEdit;
- private System.Windows.Forms.ToolBarButton tBtnDelete;
- private System.Windows.Forms.ToolBarButton tBtnSubmit;
- private System.Windows.Forms.ToolBarButton tBtnCancel;
- private System.Windows.Forms.ToolBarButton tBtnQuit;
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.TextBox txt2;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Button btnSearch;
- private System.Windows.Forms.TextBox txt1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.TextBox txt3;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.DataGrid dataGrid1;
- private System.Windows.Forms.GroupBox groupBox2;
- private System.Windows.Forms.DataGrid dataGrid2;
- private System.Data.SqlClient.SqlDataAdapter da1;
- private System.Data.SqlClient.SqlDataAdapter da2;
- private 财务管理系统.DataSet1 dataSet11;
- private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
- private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
- private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2;
- private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.TextBox txt4;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.Label label6;
- private System.Windows.Forms.Label label7;
- private System.Windows.Forms.ComboBox comboBox1;
- private System.Windows.Forms.Label label8;
- private System.Windows.Forms.Label label9;
- private System.Windows.Forms.Label label10;
- private System.Windows.Forms.Label label11;
- private System.Windows.Forms.TextBox txt5;
- private System.Windows.Forms.TextBox txt6;
- private System.Windows.Forms.TextBox txt7;
- private System.Windows.Forms.TextBox txt8;
- private System.Windows.Forms.TextBox txt9;
- private System.Windows.Forms.TextBox txt10;
- private System.Windows.Forms.Label label12;
- private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
- private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
- private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
- private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
- private System.Data.SqlClient.SqlConnection sqlConnection1;
- private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
- private System.ComponentModel.IContainer components;
- public WarrentInput()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(WarrentInput));
- this.imageList1 = new System.Windows.Forms.ImageList(this.components);
- this.toolBar1 = new System.Windows.Forms.ToolBar();
- this.tBtnFirst = new System.Windows.Forms.ToolBarButton();
- this.tBtnPre = new System.Windows.Forms.ToolBarButton();
- this.tBtnNext = new System.Windows.Forms.ToolBarButton();
- this.tBtnLast = new System.Windows.Forms.ToolBarButton();
- this.tBtnNew = new System.Windows.Forms.ToolBarButton();
- this.tBtnEdit = new System.Windows.Forms.ToolBarButton();
- this.tBtnDelete = new System.Windows.Forms.ToolBarButton();
- this.tBtnSubmit = new System.Windows.Forms.ToolBarButton();
- this.tBtnCancel = new System.Windows.Forms.ToolBarButton();
- this.tBtnQuit = new System.Windows.Forms.ToolBarButton();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.txt2 = new System.Windows.Forms.TextBox();
- this.label1 = new System.Windows.Forms.Label();
- this.btnSearch = new System.Windows.Forms.Button();
- this.txt1 = new System.Windows.Forms.TextBox();
- this.label2 = new System.Windows.Forms.Label();
- this.txt3 = new System.Windows.Forms.TextBox();
- this.label3 = new System.Windows.Forms.Label();
- this.dataGrid1 = new System.Windows.Forms.DataGrid();
- this.dataSet11 = new 财务管理系统.DataSet1();
- this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
- this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();
- this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridTextBoxColumn();
- this.dataGridTextBoxColumn3 = new System.Windows.Forms.DataGridTextBoxColumn();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.txt4 = new System.Windows.Forms.TextBox();
- this.label4 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.txt5 = new System.Windows.Forms.TextBox();
- this.label6 = new System.Windows.Forms.Label();
- this.txt6 = new System.Windows.Forms.TextBox();
- this.label7 = new System.Windows.Forms.Label();
- this.label8 = new System.Windows.Forms.Label();
- this.txt7 = new System.Windows.Forms.TextBox();
- this.txt8 = new System.Windows.Forms.TextBox();
- this.label9 = new System.Windows.Forms.Label();
- this.label10 = new System.Windows.Forms.Label();
- this.txt9 = new System.Windows.Forms.TextBox();
- this.txt10 = new System.Windows.Forms.TextBox();
- this.label11 = new System.Windows.Forms.Label();
- this.dataGrid2 = new System.Windows.Forms.DataGrid();
- this.da1 = new System.Data.SqlClient.SqlDataAdapter();
- this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
- this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
- this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
- this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
- this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
- this.da2 = new System.Data.SqlClient.SqlDataAdapter();
- this.sqlSelectCommand2 = new System.Data.SqlClient.SqlCommand();
- this.label12 = new System.Windows.Forms.Label();
- this.groupBox1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
- this.groupBox2.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).BeginInit();
- this.SuspendLayout();
- //
- // imageList1
- //
- 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.SystemColors.ControlLightLight;
- //
- // toolBar1
- //
- this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
- this.tBtnFirst,
- this.tBtnPre,
- this.tBtnNext,
- this.tBtnLast,
- this.tBtnNew,
- this.tBtnEdit,
- this.tBtnDelete,
- this.tBtnSubmit,
- this.tBtnCancel,
- this.tBtnQuit});
- this.toolBar1.DropDownArrows = true;
- this.toolBar1.ImageList = this.imageList1;
- this.toolBar1.Location = new System.Drawing.Point(0, 0);
- this.toolBar1.Name = "toolBar1";
- this.toolBar1.ShowToolTips = true;
- this.toolBar1.Size = new System.Drawing.Size(736, 41);
- this.toolBar1.TabIndex = 29;
- this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
- //
- // tBtnFirst
- //
- this.tBtnFirst.ImageIndex = 0;
- this.tBtnFirst.Text = "首记录";
- this.tBtnFirst.ToolTipText = "首记录";
- //
- // tBtnPre
- //
- this.tBtnPre.ImageIndex = 1;
- this.tBtnPre.Text = "上一记录";
- this.tBtnPre.ToolTipText = "上一记录";
- //
- // tBtnNext
- //
- this.tBtnNext.ImageIndex = 2;
- this.tBtnNext.Text = "下一记录";
- this.tBtnNext.ToolTipText = "下一记录";
- //
- // tBtnLast
- //
- this.tBtnLast.ImageIndex = 3;
- this.tBtnLast.Text = "尾记录";
- this.tBtnLast.ToolTipText = "尾记录";
- //
- // tBtnNew
- //
- this.tBtnNew.ImageIndex = 4;
- this.tBtnNew.Text = "新增";
- this.tBtnNew.ToolTipText = "新增";
- //
- // tBtnEdit
- //
- this.tBtnEdit.ImageIndex = 5;
- this.tBtnEdit.Text = "修改";
- this.tBtnEdit.ToolTipText = "修改";
- //
- // tBtnDelete
- //
- this.tBtnDelete.ImageIndex = 6;
- this.tBtnDelete.Text = "删除";
- this.tBtnDelete.ToolTipText = "删除";
- //
- // tBtnSubmit
- //
- this.tBtnSubmit.ImageIndex = 7;
- this.tBtnSubmit.Text = "提交";
- this.tBtnSubmit.ToolTipText = "提交";
- //
- // tBtnCancel
- //
- this.tBtnCancel.ImageIndex = 8;
- this.tBtnCancel.Text = "取消";
- this.tBtnCancel.ToolTipText = "取消";
- //
- // tBtnQuit
- //
- this.tBtnQuit.ImageIndex = 9;
- this.tBtnQuit.Text = "退出";
- this.tBtnQuit.ToolTipText = "退出";
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.txt2);
- this.groupBox1.Controls.Add(this.label1);
- this.groupBox1.Controls.Add(this.btnSearch);
- this.groupBox1.Controls.Add(this.txt1);
- this.groupBox1.Controls.Add(this.label2);
- this.groupBox1.Controls.Add(this.txt3);
- this.groupBox1.Controls.Add(this.label3);
- this.groupBox1.Location = new System.Drawing.Point(0, 48);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(728, 56);
- this.groupBox1.TabIndex = 28;
- this.groupBox1.TabStop = false;
- //
- // txt2
- //
- this.txt2.Location = new System.Drawing.Point(328, 24);
- this.txt2.Name = "txt2";
- this.txt2.TabIndex = 2;
- this.txt2.Text = "";
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(272, 28);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(56, 16);
- this.label1.TabIndex = 1;
- this.label1.Text = "会计期间";
- //
- // btnSearch
- //
- this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
- this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
- this.btnSearch.Location = new System.Drawing.Point(16, 24);
- this.btnSearch.Name = "btnSearch";
- this.btnSearch.Size = new System.Drawing.Size(72, 23);
- this.btnSearch.TabIndex = 0;
- this.btnSearch.Text = " 搜索";
- this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
- //
- // txt1
- //
- this.txt1.Location = new System.Drawing.Point(168, 24);
- this.txt1.Name = "txt1";
- this.txt1.TabIndex = 2;
- this.txt1.Text = "";
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(104, 28);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(56, 16);
- this.label2.TabIndex = 1;
- this.label2.Text = "凭证编号";
- //
- // txt3
- //
- this.txt3.Location = new System.Drawing.Point(504, 24);
- this.txt3.Name = "txt3";
- this.txt3.TabIndex = 2;
- this.txt3.Text = "";
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(448, 28);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(56, 16);
- this.label3.TabIndex = 1;
- this.label3.Text = "日期";
- //
- // dataGrid1
- //
- this.dataGrid1.CaptionVisible = false;
- this.dataGrid1.DataMember = "凭证表";
- this.dataGrid1.DataSource = this.dataSet11;
- this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGrid1.Location = new System.Drawing.Point(0, 104);
- this.dataGrid1.Name = "dataGrid1";
- this.dataGrid1.ReadOnly = true;
- this.dataGrid1.RowHeaderWidth = 20;
- this.dataGrid1.Size = new System.Drawing.Size(272, 416);
- this.dataGrid1.TabIndex = 30;
- this.dataGrid1.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
- this.dataGridTableStyle1});
- this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
- //
- // dataSet11
- //
- this.dataSet11.DataSetName = "DataSet1";
- this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
- //
- // dataGridTableStyle1
- //
- this.dataGridTableStyle1.DataGrid = this.dataGrid1;
- this.dataGridTableStyle1.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
- this.dataGridTextBoxColumn1,
- this.dataGridTextBoxColumn2,
- this.dataGridTextBoxColumn3});
- this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGridTableStyle1.MappingName = "凭证表";
- this.dataGridTableStyle1.RowHeaderWidth = 20;
- //
- // dataGridTextBoxColumn1
- //
- this.dataGridTextBoxColumn1.Format = "";
- this.dataGridTextBoxColumn1.FormatInfo = null;
- this.dataGridTextBoxColumn1.HeaderText = "凭证编号";
- this.dataGridTextBoxColumn1.MappingName = "凭证编号";
- this.dataGridTextBoxColumn1.Width = 80;
- //
- // dataGridTextBoxColumn2
- //
- this.dataGridTextBoxColumn2.Format = "";
- this.dataGridTextBoxColumn2.FormatInfo = null;
- this.dataGridTextBoxColumn2.HeaderText = "会计期间";
- this.dataGridTextBoxColumn2.MappingName = "会计期间";
- this.dataGridTextBoxColumn2.Width = 60;
- //
- // dataGridTextBoxColumn3
- //
- this.dataGridTextBoxColumn3.Format = "";
- this.dataGridTextBoxColumn3.FormatInfo = null;
- this.dataGridTextBoxColumn3.HeaderText = "日期";
- this.dataGridTextBoxColumn3.MappingName = "日期";
- this.dataGridTextBoxColumn3.Width = 90;
- //
- // groupBox2
- //
- this.groupBox2.Controls.Add(this.comboBox1);
- this.groupBox2.Controls.Add(this.txt4);
- this.groupBox2.Controls.Add(this.label4);
- this.groupBox2.Controls.Add(this.label5);
- this.groupBox2.Controls.Add(this.txt5);
- this.groupBox2.Controls.Add(this.label6);
- this.groupBox2.Controls.Add(this.txt6);
- this.groupBox2.Controls.Add(this.label7);
- this.groupBox2.Controls.Add(this.label8);
- this.groupBox2.Controls.Add(this.txt7);
- this.groupBox2.Controls.Add(this.txt8);
- this.groupBox2.Controls.Add(this.label9);
- this.groupBox2.Controls.Add(this.label10);
- this.groupBox2.Controls.Add(this.txt9);
- this.groupBox2.Controls.Add(this.txt10);
- this.groupBox2.Controls.Add(this.label11);
- this.groupBox2.Location = new System.Drawing.Point(272, 104);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(456, 136);
- this.groupBox2.TabIndex = 31;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "凭证详细信息";
- //
- // comboBox1
- //
- this.comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "凭证表.凭证字号"));
- this.comboBox1.Enabled = false;
- this.comboBox1.Items.AddRange(new object[] {
- "付",
- "收",
- "转"});
- this.comboBox1.Location = new System.Drawing.Point(144, 48);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(88, 20);
- this.comboBox1.TabIndex = 2;
- //
- // txt4
- //
- this.txt4.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "凭证表.凭证编号"));
- this.txt4.Location = new System.Drawing.Point(24, 48);
- this.txt4.Name = "txt4";
- this.txt4.ReadOnly = true;
- this.txt4.TabIndex = 1;
- this.txt4.Text = "";
- //
- // label4
- //
- this.label4.Location = new System.Drawing.Point(24, 32);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(72, 16);
- this.label4.TabIndex = 0;
- this.label4.Text = "凭证编号";
- //
- // label5
- //
- this.label5.Location = new System.Drawing.Point(144, 32);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(72, 16);
- this.label5.TabIndex = 0;
- this.label5.Text = "凭证字号";
- //
- // txt5
- //
- this.txt5.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "凭证表.日期"));
- this.txt5.Location = new System.Drawing.Point(256, 48);
- this.txt5.Name = "txt5";
- this.txt5.ReadOnly = true;
- this.txt5.TabIndex = 1;
- this.txt5.Text = "";
- //
- // label6
- //
- this.label6.Location = new System.Drawing.Point(376, 32);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(72, 16);
- this.label6.TabIndex = 0;
- this.label6.Text = "制单人";
- //
- // txt6
- //
- this.txt6.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "凭证表.制单"));
- this.txt6.Location = new System.Drawing.Point(376, 48);
- this.txt6.Name = "txt6";
- this.txt6.ReadOnly = true;
- this.txt6.Size = new System.Drawing.Size(72, 21);
- this.txt6.TabIndex = 1;
- this.txt6.Text = "";
- //
- // label7
- //
- this.label7.Location = new System.Drawing.Point(256, 32);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(72, 16);
- this.label7.TabIndex = 0;
- this.label7.Text = "日期";
- //
- // label8
- //
- this.label8.Location = new System.Drawing.Point(24, 88);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(72, 16);
- this.label8.TabIndex = 0;
- this.label8.Text = "会计期间";
- //
- // txt7
- //
- this.txt7.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "凭证表.会计期间"));
- this.txt7.Location = new System.Drawing.Point(24, 104);
- this.txt7.Name = "txt7";
- this.txt7.ReadOnly = true;
- this.txt7.Size = new System.Drawing.Size(96, 21);
- this.txt7.TabIndex = 1;
- this.txt7.Text = "";
- //
- // txt8
- //
- this.txt8.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "凭证表.过账状态"));
- this.txt8.Location = new System.Drawing.Point(136, 104);
- this.txt8.Name = "txt8";
- this.txt8.ReadOnly = true;
- this.txt8.Size = new System.Drawing.Size(88, 21);
- this.txt8.TabIndex = 1;
- this.txt8.Text = "";
- //
- // label9
- //
- this.label9.Location = new System.Drawing.Point(136, 88);
- this.label9.Name = "label9";
- this.label9.Size = new System.Drawing.Size(72, 16);
- this.label9.TabIndex = 0;
- this.label9.Text = "过帐状态";
- //
- // label10
- //
- this.label10.Location = new System.Drawing.Point(240, 88);
- this.label10.Name = "label10";
- this.label10.Size = new System.Drawing.Size(72, 16);
- this.label10.TabIndex = 0;
- this.label10.Text = "借方合计";
- //
- // txt9
- //
- this.txt9.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "凭证表.借方合计"));
- this.txt9.Location = new System.Drawing.Point(240, 104);
- this.txt9.Name = "txt9";
- this.txt9.ReadOnly = true;
- this.txt9.TabIndex = 1;
- this.txt9.Text = "";
- //
- // txt10
- //
- this.txt10.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "凭证表.贷方合计"));
- this.txt10.Location = new System.Drawing.Point(352, 104);
- this.txt10.Name = "txt10";
- this.txt10.ReadOnly = true;
- this.txt10.Size = new System.Drawing.Size(96, 21);
- this.txt10.TabIndex = 1;
- this.txt10.Text = "";
- //
- // label11
- //
- this.label11.Location = new System.Drawing.Point(360, 88);
- this.label11.Name = "label11";
- this.label11.Size = new System.Drawing.Size(72, 16);
- this.label11.TabIndex = 0;
- this.label11.Text = "贷方合计";
- //
- // dataGrid2
- //
- this.dataGrid2.CaptionVisible = false;
- this.dataGrid2.DataMember = "";
- this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGrid2.Location = new System.Drawing.Point(280, 256);
- this.dataGrid2.Name = "dataGrid2";
- this.dataGrid2.ReadOnly = true;
- this.dataGrid2.Size = new System.Drawing.Size(448, 264);
- this.dataGrid2.TabIndex = 32;
- this.dataGrid2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dataGrid2_MouseDown);
- this.dataGrid2.DoubleClick += new System.EventHandler(this.dataGrid2_DoubleClick);
- this.dataGrid2.CurrentCellChanged += new System.EventHandler(this.dataGrid2_CurrentCellChanged);
- //
- // da1
- //
- this.da1.DeleteCommand = this.sqlDeleteCommand1;
- this.da1.InsertCommand = this.sqlInsertCommand1;
- this.da1.SelectCommand = this.sqlSelectCommand1;
- this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
- new System.Data.Common.DataTableMapping("Table", "凭证表", new System.Data.Common.DataColumnMapping[] {
- new System.Data.Common.DataColumnMapping("凭证编号", "凭证编号"),
- new System.Data.Common.DataColumnMapping("会计期间", "会计期间"),
- new System.Data.Common.DataColumnMapping("凭证字号", "凭证字号"),
- new System.Data.Common.DataColumnMapping("日期", "日期"),
- new System.Data.Common.DataColumnMapping("附单据", "附单据"),
- new System.Data.Common.DataColumnMapping("制单", "制单"),
- new System.Data.Common.DataColumnMapping("借方合计", "借方合计"),
- new System.Data.Common.DataColumnMapping("贷方合计", "贷方合计"),
- new System.Data.Common.DataColumnMapping("过账状态", "过账状态"),
- new System.Data.Common.DataColumnMapping("凭证状态", "凭证状态")})});
- this.da1.UpdateCommand = this.sqlUpdateCommand1;
- //
- // sqlDeleteCommand1
- //
- this.sqlDeleteCommand1.CommandText = @"DELETE FROM 凭证表 WHERE (凭证编号 = @Original_凭证编号) AND (会计期间 = @Original_会计期间 OR @Original_会计期间 IS NULL AND 会计期间 IS NULL) AND (借方合计 = @Original_借方合计 OR @Original_借方合计 IS NULL AND 借方合计 IS NULL) AND (凭证字号 = @Original_凭证字号 OR @Original_凭证字号 IS NULL AND 凭证字号 IS NULL) AND (凭证状态 = @Original_凭证状态 OR @Original_凭证状态 IS NULL AND 凭证状态 IS NULL) AND (制单 = @Original_制单 OR @Original_制单 IS NULL AND 制单 IS NULL) AND (日期 = @Original_日期 OR @Original_日期 IS NULL AND 日期 IS NULL) AND (贷方合计 = @Original_贷方合计 OR @Original_贷方合计 IS NULL AND 贷方合计 IS NULL) AND (过账状态 = @Original_过账状态 OR @Original_过账状态 IS NULL AND 过账状态 IS NULL) AND (附单据 = @Original_附单据 OR @Original_附单据 IS NULL AND 附单据 IS NULL)";
- this.sqlDeleteCommand1.Connection = this.sqlConnection1;
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_凭证编号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "凭证编号", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_会计期间", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "会计期间", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_借方合计", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "借方合计", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_凭证字号", System.Data.SqlDbType.VarChar, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "凭证字号", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_凭证状态", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "凭证状态", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_制单", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "制单", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_日期", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "日期", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_贷方合计", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "贷方合计", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_过账状态", System.Data.SqlDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "过账状态", System.Data.DataRowVersion.Original, null));
- this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_附单据", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "附单据", System.Data.DataRowVersion.Original, null));
- //
- // sqlConnection1
- //
- this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;initial catalo" +
- "g=caiwubook;persist security info=False";
- //
- // sqlInsertCommand1
- //
- this.sqlInsertCommand1.CommandText = "INSERT INTO 凭证表(凭证编号, 会计期间, 凭证字号, 日期, 附单据, 制单, 借方合计, 贷方合计, 过账状态, 凭证状态) VALUES (@凭" +
- "证编号, @会计期间, @凭证字号, @日期, @附单据, @制单, @借方合计, @贷方合计, @过账状态, @凭证状态); SELECT 凭证编号, 会计期" +
- "间, 凭证字号, 日期, 附单据, 制单, 借方合计, 贷方合计, 过账状态, 凭证状态 FROM 凭证表 WHERE (凭证编号 = @凭证编号) ORDER" +
- " BY 凭证编号";
- this.sqlInsertCommand1.Connection = this.sqlConnection1;
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@凭证编号", System.Data.SqlDbType.VarChar, 10, "凭证编号"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@会计期间", System.Data.SqlDbType.Int, 4, "会计期间"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@凭证字号", System.Data.SqlDbType.VarChar, 2, "凭证字号"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@日期", System.Data.SqlDbType.DateTime, 8, "日期"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@附单据", System.Data.SqlDbType.Int, 4, "附单据"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@制单", System.Data.SqlDbType.VarChar, 20, "制单"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@借方合计", System.Data.SqlDbType.Money, 8, "借方合计"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@贷方合计", System.Data.SqlDbType.Money, 8, "贷方合计"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@过账状态", System.Data.SqlDbType.VarChar, 4, "过账状态"));
- this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@凭证状态", System.Data.SqlDbType.VarChar, 10, "凭证状态"));
- //
- // sqlSelectCommand1
- //
- this.sqlSelectCommand1.CommandText = "SELECT 凭证编号, 会计期间, 凭证字号, 日期, 附单据, 制单, 借方合计, 贷方合计, 过账状态, 凭证状态 FROM 凭证表 WHERE (凭证编号" +
- " LIKE @Param4) AND (会计期间 LIKE @Param5) AND (日期 LIKE @Param6) ORDER BY 凭证编号";
- this.sqlSelectCommand1.Connection = this.sqlConnection1;
- this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param4", System.Data.SqlDbType.VarChar, 10, "凭证编号"));
- this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param5", System.Data.SqlDbType.VarChar, 10, "会计期间"));
- this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param6", System.Data.SqlDbType.DateTime, 8, "日期"));
- //
- // sqlUpdateCommand1
- //
- this.sqlUpdateCommand1.CommandText = @"UPDATE 凭证表 SET 凭证编号 = @凭证编号, 会计期间 = @会计期间, 凭证字号 = @凭证字号, 日期 = @日期, 附单据 = @附单据, 制单 = @制单, 借方合计 = @借方合计, 贷方合计 = @贷方合计, 过账状态 = @过账状态, 凭证状态 = @凭证状态 WHERE (凭证编号 = @Original_凭证编号) AND (会计期间 = @Original_会计期间 OR @Original_会计期间 IS NULL AND 会计期间 IS NULL) AND (借方合计 = @Original_借方合计 OR @Original_借方合计 IS NULL AND 借方合计 IS NULL) AND (凭证字号 = @Original_凭证字号 OR @Original_凭证字号 IS NULL AND 凭证字号 IS NULL) AND (凭证状态 = @Original_凭证状态 OR @Original_凭证状态 IS NULL AND 凭证状态 IS NULL) AND (制单 = @Original_制单 OR @Original_制单 IS NULL AND 制单 IS NULL) AND (日期 = @Original_日期 OR @Original_日期 IS NULL AND 日期 IS NULL) AND (贷方合计 = @Original_贷方合计 OR @Original_贷方合计 IS NULL AND 贷方合计 IS NULL) AND (过账状态 = @Original_过账状态 OR @Original_过账状态 IS NULL AND 过账状态 IS NULL) AND (附单据 = @Original_附单据 OR @Original_附单据 IS NULL AND 附单据 IS NULL); SELECT 凭证编号, 会计期间, 凭证字号, 日期, 附单据, 制单, 借方合计, 贷方合计, 过账状态, 凭证状态 FROM 凭证表 WHERE (凭证编号 = @凭证编号) ORDER BY 凭证编号";
- this.sqlUpdateCommand1.Connection = this.sqlConnection1;
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@凭证编号", System.Data.SqlDbType.VarChar, 10, "凭证编号"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@会计期间", System.Data.SqlDbType.Int, 4, "会计期间"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@凭证字号", System.Data.SqlDbType.VarChar, 2, "凭证字号"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@日期", System.Data.SqlDbType.DateTime, 8, "日期"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@附单据", System.Data.SqlDbType.Int, 4, "附单据"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@制单", System.Data.SqlDbType.VarChar, 20, "制单"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@借方合计", System.Data.SqlDbType.Money, 8, "借方合计"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@贷方合计", System.Data.SqlDbType.Money, 8, "贷方合计"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@过账状态", System.Data.SqlDbType.VarChar, 4, "过账状态"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@凭证状态", System.Data.SqlDbType.VarChar, 10, "凭证状态"));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_凭证编号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "凭证编号", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_会计期间", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "会计期间", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_借方合计", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "借方合计", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_凭证字号", System.Data.SqlDbType.VarChar, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "凭证字号", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_凭证状态", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "凭证状态", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_制单", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "制单", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_日期", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "日期", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_贷方合计", System.Data.SqlDbType.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "贷方合计", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_过账状态", System.Data.SqlDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "过账状态", System.Data.DataRowVersion.Original, null));
- this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_附单据", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "附单据", System.Data.DataRowVersion.Original, null));
- //
- // da2
- //
- this.da2.SelectCommand = this.sqlSelectCommand2;
- this.da2.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
- new System.Data.Common.DataTableMapping("Table", "分录表", new System.Data.Common.DataColumnMapping[] {
- new System.Data.Common.DataColumnMapping("科目名称", "科目名称"),
- new System.Data.Common.DataColumnMapping("编号", "编号"),
- new System.Data.Common.DataColumnMapping("凭证编号", "凭证编号"),
- new System.Data.Common.DataColumnMapping("摘要", "摘要"),
- new System.Data.Common.DataColumnMapping("科目代码", "科目代码"),
- new System.Data.Common.DataColumnMapping("借方", "借方"),
- new System.Data.Common.DataColumnMapping("贷方", "贷方"),
- new System.Data.Common.DataColumnMapping("数量", "数量"),
- new System.Data.Common.DataColumnMapping("单价", "单价"),
- new System.Data.Common.DataColumnMapping("结算方式", "结算方式"),
- new System.Data.Common.DataColumnMapping("结算号", "结算号"),
- new System.Data.Common.DataColumnMapping("结算日期", "结算日期")})});
- //
- // sqlSelectCommand2
- //
- this.sqlSelectCommand2.CommandText = "SELECT b.科目名称, a.编号, a.凭证编号, a.摘要, a.科目代码, a.借方, a.贷方, a.数量, a.单价, a.结算方式, a.结算号," +
- " a.结算日期 FROM 分录表 a INNER JOIN 科目表 b ON a.科目代码 = b.科目代码 WHERE (a.凭证编号 = @Param2)";
- this.sqlSelectCommand2.Connection = this.sqlConnection1;
- this.sqlSelectCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.VarChar, 10, "凭证编号"));
- //
- // label12
- //
- this.label12.Location = new System.Drawing.Point(280, 242);
- this.label12.Name = "label12";
- this.label12.Size = new System.Drawing.Size(184, 14);
- this.label12.TabIndex = 33;
- this.label12.Text = "双击新行前的导航栏选择明细";
- //
- // WarrentInput
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(736, 525);
- this.Controls.Add(this.label12);
- this.Controls.Add(this.dataGrid2);
- this.Controls.Add(this.dataGrid1);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.toolBar1);
- this.Controls.Add(this.groupBox2);
- this.Name = "WarrentInput";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "【会计凭证输入】";
- this.Load += new System.EventHandler(this.WarrentInput_Load);
- this.groupBox1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
- this.groupBox2.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- //-------------创建窗体时,读入全部数据------------
- private void WarrentInput_Load(object sender, System.EventArgs e)
- {
- da1.SelectCommand.Parameters[0].Value="%%";//设置参数
- da1.SelectCommand.Parameters[1].SqlDbType=System.Data.SqlDbType.VarChar;
- da1.SelectCommand.Parameters[2].SqlDbType=System.Data.SqlDbType.VarChar;
- da1.SelectCommand.Parameters[1].Value="%%";
- da1.SelectCommand.Parameters[2].Value="%%";
- da1.Fill(dataSet11.凭证表);
- DataGridStateControl();//设置分录表表格
- //最初显示时,分录表显示第一个凭证记录的明细信息
- da2.SelectCommand.Parameters[0].Value=txt4.Text.Trim();
- newTable.Clear();
- da2.Fill(newTable);
- dataGrid2.ReadOnly=true;
- //创建窗体时处于浏览状态,不允许双击分录表添加记录
- this.enableDoubleClick=false;
- //绑定数据导航控制
- cmOrders=(CurrencyManager) BindingContext[dataSet11,"凭证表"];
- }
- //----------设置明细表格各列的属性----------
- private void DataGridStateControl()
- {
- newTable = new DataTable();
- newTable.Columns.Add("科目代码",typeof(string));
- newTable.Columns.Add("科目名称",typeof(string));
- newTable.Columns.Add("借方",typeof(decimal));
- newTable.Columns.Add("贷方",typeof(decimal));
- newTable.Columns.Add("摘要",typeof(string));
- this.dataGrid2.DataSource = newTable;
- newTable.Rows.Add(newTable.NewRow()); //向表中添加一行
- DataGridTableStyle ts = new DataGridTableStyle();
- DataGridTextBoxColumn aColumnTextColumn;
- ts.AllowSorting = false;
- ts.AlternatingBackColor = Color.LightGray;
- ts.MappingName = newTable.TableName;
- int numCols = newTable.Columns.Count;
- for (int i = 0;i< numCols;i++)
- {
- aColumnTextColumn = new DataGridTextBoxColumn();
- if( i==0 || i==1 )//表中允许编辑【借方】,【贷方】和【备注】三个字段
- {
- aColumnTextColumn.ReadOnly=true;
- }
- if ( i == 1 )//当鼠标单击第1列时,允许响应
- {
- aColumnTextColumn.TextBox.MouseDown += new MouseEventHandler(TextBoxMouseDownHandler);
- }
- if(i==1)
- {
- aColumnTextColumn.Width=100;//设置科目名称宽度
- }
- if ( i == 4 )
- {
- aColumnTextColumn.Width = 160;//设置宽度
- }
- aColumnTextColumn.MappingName = newTable.Columns[i].ColumnName;
- aColumnTextColumn.HeaderText = newTable.Columns[i].ColumnName;
- aColumnTextColumn.NullText = "";
- aColumnTextColumn.Format = "N"; //设置为数字格式显示
- ts.GridColumnStyles.Add(aColumnTextColumn);
- }
- dataGrid2.TableStyles.Add(ts);
- }
- //------------根据输入信息来检索数据-------------
- private void btnSearch_Click(object sender, System.EventArgs e)
- {
- da1.SelectCommand.Parameters[0].Value="%%";
- da1.SelectCommand.Parameters[1].Value="%%";
- da1.SelectCommand.Parameters[2].Value="%%";
- //根据用户在文本框中的输入来设置SQL查询的参数
- if(txt1.Text.Trim()!="")
- {
- da1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%";
- }
- if(txt2.Text.Trim()!="")
- {
- da1.SelectCommand.Parameters[1].Value="%"+txt2.Text.Trim()+"%";
- }
- if(txt3.Text.Trim()!="")
- {
- da1.SelectCommand.Parameters[2].Value="%"+txt3.Text.Trim()+"%";
- }
- //清空数据表,并根据新设置的查询参数重新填充
- dataSet11.凭证表.Clear();
- da1.Fill(dataSet11);
- //显示分录数据
- da2.SelectCommand.Parameters[0].Value=txt4.Text.Trim();
- newTable.Clear();
- da2.Fill(newTable);
- dataGrid2.ReadOnly=true;
- }
- //---------根据指针指向的凭证表数据显示其分录表数据---------
- private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
- {
- da2.SelectCommand.Parameters[0].Value=txt4.Text.Trim();
- newTable.Clear();
- da2.Fill(newTable);
- dataGrid2.ReadOnly=true;
- }
- //----------双击分录表表格,添加新的分录记录----------
- private void dataGrid2_DoubleClick(object sender, System.EventArgs e)
- {
- if(this.enableDoubleClick==true)
- {
- this.doubleClicked();
- }
- }
- //--------------确定鼠标在表格中的点击模式--------------
- private void dataGrid2_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- //获取当前点击鼠标时的时间
- DataGrid myGrid = (DataGrid)sender;
- System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
- myHitTest = dataGrid2.HitTest(e.X,e.Y);
- if ( myHitTest.Type == System.Windows.Forms.DataGrid.HitTestType.Cell )
- gridMouseDownTime = DateTime.Now;
- }
- //------------处理鼠标在dataGrid上的单击事件-----------
- private void TextBoxMouseDownHandler(object sender, MouseEventArgs e )
- {
- //第一个判断条件:在单元格的textbox中的双击(即单击DataCell,使它获得焦点后,然后再响应该Cell中的双击事件)
- //第二个判断条件:DataGrid 的 DoubleClick(直接双击Cell就响应双击事件,无须先单击Cell,使它获得焦点,然后再响应双击事件)
- //判断时间间隔是否小于控制面板中所定义的双击间隔时间
- if((e.Button == MouseButtons.Left && e.Clicks == 2 || DateTime.Now < gridMouseDownTime.AddMilliseconds(SystemInformation.DoubleClickTime))&&(this.enableDoubleClick==true))
- {
- this.doubleClicked();
- }
- }
- //-------双击分录表表格,添加新的分录数据-----------
- private void doubleClicked()
- {
- newTable.Rows.Add(newTable.NewRow()); //向表中添加一行,保持总有一个新行
- SelectSubject newFrm=new SelectSubject();
- newFrm.ShowDialog();
- int rowNumber=dataGrid2.CurrentCell.RowNumber;
- dataGrid2[rowNumber,0]=mID;
- dataGrid2[rowNumber,1]=mName;
- dataGrid2[rowNumber,2]="0";
- dataGrid2[rowNumber,3]="0";
- SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
- }
- //------------计算输入的分录表借贷总额-------------
- private void dataGrid2_CurrentCellChanged(object sender, System.EventArgs e)
- {
- if(this.enableDoubleClick==true)
- {
- int rowCount=newTable.Rows.Count;
- decimal debit=0;
- decimal loan=0;
- for(int i=0;i<rowCount;i++)
- {
- if(dataGrid2[i,2]!=DBNull.Value)
- {
- debit+=Convert.ToDecimal(dataGrid2[i,2]);
- loan+=Convert.ToDecimal(dataGrid2[i,3]);
- }
- }
- txt9.Text=debit.ToString();
- txt10.Text=loan.ToString();
- }
- }
- //--------------工具栏事务处理----------------
- private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
- {
- if (e.Button.ToolTipText == "首记录")
- {
- this.dataGrid1.UnSelect(cmOrders.Position); //取消原选中的行
- cmOrders.Position = 0;
- this.dataGrid1.Select(cmOrders.Position); //选中当前行
- this.dataGrid1.CurrentRowIndex = cmOrders.Position; //移动表头指示图标
- return;
- }
- if (e.Button.ToolTipText == "上一记录")
- {
- if (cmOrders.Position >= 0)
- {
- this.dataGrid1.UnSelect(cmOrders.Position);
- cmOrders.Position--;
- this.dataGrid1.Select(cmOrders.Position);
- this.dataGrid1.CurrentRowIndex = cmOrders.Position;
- }
- return;
- }
- if (e.Button.ToolTipText == "下一记录")
- {
- if (cmOrders.Position <= cmOrders.Count-1)
- {
- this.dataGrid1.UnSelect(cmOrders.Position);
- cmOrders.Position++;
- this.dataGrid1.Select(cmOrders.Position);
- this.dataGrid1.CurrentRowIndex = cmOrders.Position;
- }
- return;
- }
- if (e.Button.ToolTipText == "尾记录")
- {
- this.dataGrid1.UnSelect(cmOrders.Position);
- cmOrders.Position = cmOrders.Count-1;
- this.dataGrid1.Select(cmOrders.Position);
- this.dataGrid1.CurrentRowIndex = cmOrders.Position;
- return;
- }
- if(e.Button.ToolTipText=="新增")
- {
- cmOrders.AddNew();
- //设置按钮
- SetModifyMode(true);
- //设置默认值
- //查询当前会计期间
- string strConn = "workstation id=localhost;Integrated Security=SSPI;database=caiwubook";
- SqlConnection cn=new SqlConnection(strConn);
- cn.Open();
- SqlCommand cmd=cn.CreateCommand();
- cmd.CommandText="select 取值 from 系统参数表 where 参数名称='当前会计期间'";
- txt7.Text=cmd.ExecuteScalar().ToString();//读入当前会计期间
- //自动计算最大编号
- cmd.CommandText="select max(凭证编号) 最大编号 from 凭证表";
- object maxResult=cmd.ExecuteScalar();
- int maxID=1;
- if(maxResult!=System.DBNull.Value)//如果当前凭证表为空,则新编号为000001
- maxID=Convert.ToInt32(maxResult)+1;
- int length=maxID.ToString().Length;
- switch(length)
- {
- case 1:
- txt4.Text="00000"+maxID.ToString();
- break;
- case 2:
- txt4.Text="0000"+maxID.ToString();
- break;
- case 3:
- txt4.Text="000"+maxID.ToString();
- break;
- case 4:
- txt4.Text="00"+maxID.ToString();
- break;
- case 5:
- txt4.Text="0"+maxID.ToString();
- break;
- }
- txt5.Text=DateTime.Now.ToShortDateString();//当前时间
- txt8.Text="未过";//新增凭证的状态都是"未过"
- comboBox1.SelectedText="收";//设置凭证字号
- //允许双击分录表表格添加分录数据
- this.enableDoubleClick=true;
- dataGrid2.ReadOnly=false;
- DataGridStateControl();
- newTable.Clear();
- }
- if(e.Button.ToolTipText=="修改")
- {
- SetModifyMode(true);
- this.enableDoubleClick=true;
- dataGrid2.ReadOnly=false;
- }
- if(e.Button.ToolTipText=="删除")
- {
- DialogResult result=MessageBox.Show("将删除凭证记录以及下属的分录信息,是否确认?","删除数据",MessageBoxButtons.OKCancel);
- if(result==DialogResult.OK)
- if(cmOrders.Count>0)
- {
- try
- {
- string strConn = "workstation id=localhost;Integrated Security=SSPI;database=caiwubook";
- SqlConnection cn=new SqlConnection(strConn);
- cn.Open();
- SqlCommand cmd=cn.CreateCommand();
- cmd.CommandText="delete from 分录表 where 凭证编号='"+txt4.Text+"'";//删除分录记录
- cmd.ExecuteNonQuery();
- cmOrders.RemoveAt(cmOrders.Position);
- da1.Update(dataSet11);
- }
- catch(Exception express)
- {
- MessageBox.Show(express.ToString(),"错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
- return;
- }
- }
- else
- MessageBox.Show("表中为空,已无可删除数据","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
- }
- if(e.Button.ToolTipText=="提交")
- {
- if(txt9.Text!=txt10.Text)
- {
- MessageBox.Show("借贷双方不平衡,请检查并修改分录数据后重新输入","错误",MessageBoxButtons.OK,MessageBoxIcon.Warning);
- return;
- }
- cmOrders.EndCurrentEdit();//结束当前编辑操作并提交修改
- int rowCount=newTable.Rows.Count;
- if(rowCount==0)
- {
- MessageBox.Show("请先输入凭证表分录数据后再保存","警告",MessageBoxButtons.OK,MessageBoxIcon.Error);
- return;
- }
- try
- {
- if (dataSet11.GetChanges()!=null)
- {
- this.da1.Update(dataSet11);//首先,先保存凭证信息
- }
- string strConn = "workstation id=localhost;Integrated Security=SSPI;database=caiwubook";
- SqlConnection cn=new SqlConnection(strConn);
- cn.Open();
- SqlCommand cmd=cn.CreateCommand();
- cmd.CommandText="delete from 分录表 where 凭证编号='"+txt4.Text+"'";
- cmd.ExecuteNonQuery();//其次,再将该凭证信息对应的分录记录删除
- for(int i=0;i<rowCount;i++)//最后,再逐行重新插入分录数据
- {
- if(dataGrid2[i,0].ToString().Trim()!="")//如该行数据为空,则不保存该行
- {
- cmd.CommandText="insert into 分录表([凭证编号], [摘要], [科目代码], [借方], [贷方]) "
- +"values('"+txt4.Text+"','"+dataGrid2[i,4].ToString()+"','"+dataGrid2[i,0].ToString()
- +"',CAST('"+dataGrid2[i,2].ToString()+"'as money),CAST('"+dataGrid2[i,3].ToString()+"' as money))";
- cmd.ExecuteNonQuery();
- }
- }
- this.enableDoubleClick=false;
- }
- catch(Exception express)
- {
- MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
- dataSet11.RejectChanges();
- }
- SetModifyMode(false);
- return;
- }
- if (e.Button.ToolTipText == "取消")
- {
- try
- {
- cmOrders.CancelCurrentEdit(); //取消编辑
- SetModifyMode(false);
- if(txt4.Text.Trim()!="")//恢复显示明细信息
- {
- da2.SelectCommand.Parameters[0].Value=txt4.Text.Trim();
- newTable.Clear();
- da2.Fill(newTable);
- dataGrid2.ReadOnly=true;
- }
- }
- catch(Exception express)
- {
- MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
- }
- return;
- }
- if(e.Button.ToolTipText=="退出")
- {
- this.Close();
- }
- }
- //--------------对控件的属性做设置---------------
- private void SetModifyMode(bool blnEdit)
- {
- //设置文本框和下拉列表框属性
- txt4.ReadOnly=!blnEdit;
- txt5.ReadOnly=!blnEdit;
- comboBox1.Enabled=blnEdit;
- //设置搜索按钮属性
- btnSearch.Enabled=!blnEdit;
- //设置两个表格的ReadOnly属性
- dataGrid1.ReadOnly=!blnEdit;
- dataGrid2.ReadOnly=!blnEdit;
- }
- }
- }