📄 frmaccountset.cs
字号:
this.btnBalance.Text = "试算平衡";
this.btnBalance.Click += new System.EventHandler(this.btnBalance_Click);
//
// 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("余额方向", "余额方向")})});
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)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
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.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.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, 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.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.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "累计贷方", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=WINDOWSXP;packet size=4096;integrated security=SSPI;data source=\"." +
"\";persist security info=False;initial catalog=caiwubook";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 帐簿初始化表(科目代码, 科目名称, 累计借方, 累计贷方, 期初余额, 余额方向) VALUES (@科目代码, @科目名称, @累计借" +
"方, @累计贷方, @期初余额, @余额方向); SELECT 科目代码, 科目名称, 累计借方, 累计贷方, 期初余额, 余额方向 FROM 帐簿初始化表 W" +
"HERE (科目代码 = @科目代码)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
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.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.Money, 8, "期初余额"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@余额方向", System.Data.SqlDbType.VarChar, 4, "余额方向"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 科目代码, 科目名称, 累计借方, 累计贷方, 期初余额, 余额方向 FROM 帐簿初始化表";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// 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); SELECT 科目代码, 科目名称, 累计借方, 累计贷方, 期初余额, 余额方向 FROM 帐簿初始化表 WHERE (科目代码 = @科目代码)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
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.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.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("@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.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.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, 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.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.Money, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "累计贷方", System.Data.DataRowVersion.Original, null));
//
// da2
//
this.da2.InsertCommand = this.sqlInsertCommand2;
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("取值", "取值")})});
//
// sqlInsertCommand2
//
this.sqlInsertCommand2.CommandText = "INSERT INTO 系统参数表(参数名称, 取值) VALUES (@参数名称, @取值); SELECT 编号, 参数名称, 取值 FROM 系统参数表";
this.sqlInsertCommand2.Connection = this.sqlConnection1;
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@参数名称", System.Data.SqlDbType.VarChar, 20, "参数名称"));
this.sqlInsertCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@取值", System.Data.SqlDbType.Int, 4, "取值"));
//
// sqlSelectCommand2
//
this.sqlSelectCommand2.CommandText = "SELECT 编号, 参数名称, 取值 FROM 系统参数表";
this.sqlSelectCommand2.Connection = this.sqlConnection1;
//
// FrmAccountSet
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(688, 493);
this.Controls.Add(this.btnNewAccount);
this.Controls.Add(this.dataGrid2);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.btnUseAccount);
this.Controls.Add(this.btnBalance);
this.Name = "FrmAccountSet";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "【帐户设置】";
this.Load += new System.EventHandler(this.FrmAccountSet_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet21)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
this.ResumeLayout(false);
}
#endregion
//------------建立新窗体时,读入所有数据-------------
private void FrmAccountSet_Load(object sender, System.EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
da1.Fill(dataSet21);
da2.Fill(dataSet21);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"导致窗体加载失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
this.Cursor = Cursors.Default;
}
}
//-----------建立新帐户----------
private void btnNewAccount_Click(object sender, System.EventArgs e)
{
DialogResult result=MessageBox.Show("是否清除原有帐簿信息并初始化新帐簿?","警告",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
if(result==DialogResult.OK)
{
string strConn = "workstation id=localhost;Integrated Security=SSPI;database=caiwubook";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
SqlCommand cmd=cn.CreateCommand();
cmd.CommandText="exec sf_初始化帐户";
try
{
this.Cursor = Cursors.WaitCursor;
cmd.ExecuteNonQuery();
dataSet21.Clear();//刷新数据集
da1.Fill(dataSet21);
da2.Fill(dataSet21);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"建立新帐户失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
this.Cursor = Cursors.Default;
}
}
}
//-----------启用新帐户----------
private void btnUseAccount_Click(object sender, System.EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
da1.Update(dataSet21);//将用户对新帐簿中数据的修改提交到数据库
string strConn = "workstation id=localhost;Integrated Security=SSPI;database=caiwubook";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
SqlCommand cmd=cn.CreateCommand();
cmd.CommandText="select sum(累计借方) 借方,sum(累计贷方) 贷方 from 帐簿初始化表";
SqlDataReader dr=cmd.ExecuteReader();
dr.Read();
if(dr.GetValue(0).ToString().Trim()!=dr.GetValue(1).ToString().Trim())//判断初始化后帐簿是否平衡
{
MessageBox.Show("新帐簿初始化不平衡,请检查试算平衡表后重新输入","无法启用新帐簿",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
else
{
DialogResult result=MessageBox.Show("试算结果平衡,启用新帐簿将删除所有历史记录,是否继续?","确认启用新帐簿",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
if(result==DialogResult.OK)
{
dr.Close();
cmd.CommandText="exec sf_启用帐户";
cmd.ExecuteNonQuery();
dataSet21.Clear();//刷新数据集
da1.Fill(dataSet21);
da2.Fill(dataSet21);
MessageBox.Show("新帐户启用成功!");
}
return;
}
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"启用新帐户失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
this.Cursor = Cursors.Default;
}
}
//----------新帐户的试算平衡--------
private void btnBalance_Click(object sender, System.EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
da1.Update(dataSet21);//将用户对新帐簿中数据的修改提交到数据库
FrmTrialBalance newFrm=new FrmTrialBalance(true);
newFrm.Text+="初始化帐户";
newFrm.Show();
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"连接失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
this.Cursor = Cursors.Default;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -