📄 computeform.aspx.cs
字号:
//文件名:ComputeForm.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class DepreciationManage_ComputeForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string MyForbidString = Session["MyForbid"].ToString();
if (MyForbidString.IndexOf("B1") > 1)
{
Server.Transfer("~/SystemManage/AllErrorHelp.aspx");
}
string MyImportInfo = "导入折旧数据意味着本月正在计算的折旧数据将被删除,是否继续?";
this.Button1.OnClientClick = "return confirm('" + MyImportInfo + "')";
string MyExportInfo = "转入累计折旧意味着本月的折旧数据将入账并且无法再更改,是否继续?";
this.Button2.OnClientClick = "return confirm('" + MyExportInfo + "')";
}
protected void Button1_Click(object sender, EventArgs e)
{//导入折旧数据
String MySQLConnectionString = ConfigurationManager.ConnectionStrings["MyAssetsDBConnectionString"].ConnectionString;
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
string MySQL = "DELETE FROM 折旧核算表;";
MySQL += "INSERT INTO 折旧核算表 (使用部门,所属类别,资产编号,资产名称,资产原值,累计折旧,折旧方法,折旧月数,已提月数,月度折旧额,预计净残值) SELECT 使用部门,所属类别,资产编号,资产名称,资产原值,累计折旧,折旧方法,折旧月数,已提月数,月度折旧额,预计净残值 FROM 基本档案 WHERE (已提月数<折旧月数) AND (资产编号 NOT IN (SELECT 资产编号 FROM 减少资产));";
MySQL += "UPDATE 折旧核算表 SET 折旧年份=" + this.DropDownList1.SelectedValue.ToString() + ",折旧月份=" + this.DropDownList2.SelectedValue.ToString();
SqlCommand MyCommand = MyConnection.CreateCommand();
MyCommand.CommandText = MySQL;
MyCommand.ExecuteNonQuery();
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
this.GridView1.DataBind();
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{//弹出删除操作确认对话框
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button MyButton = (Button)e.Row.FindControl("Button1");
MyButton.OnClientClick = "return confirm('是否确认删除当前选择的记录?')";
}
}
protected void Button2_Click(object sender, EventArgs e)
{//转入累计折旧
String MySQLConnectionString = ConfigurationManager.ConnectionStrings["MyAssetsDBConnectionString"].ConnectionString;
string MySQL = "SELECT * FROM [折旧核算表]";
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
DataTable MyComputeTable = new DataTable();
SqlDataAdapter MyAdatper = new SqlDataAdapter(MySQL, MyConnection);
MyAdatper.Fill(MyComputeTable);
SqlCommand MyCommand;
string MyInfo = "成功计提该月的固定资产累计折旧值!";
foreach (DataRow MyRow in MyComputeTable.Rows)
{
string My资产编号 = MyRow[3].ToString();
string My折旧年份 = MyRow[12].ToString();
string My折旧月份 = MyRow[13].ToString();
MySQL = "Select COUNT(*) From 累计折旧表 Where 折旧年份=" + My折旧年份 + " AND 折旧月份=" + My折旧月份 + " AND 资产编号='" + My资产编号 + "'";
MyCommand = new SqlCommand(MySQL, MyConnection);
int MyCount = (int)MyCommand.ExecuteScalar();
if (MyCount > 0)
{
MyInfo = "计提该月的固定资产累计折旧值可能有错误!";
continue;
}
MySQL = "INSERT INTO 累计折旧表([资产编号],[折旧方法],[月度折旧额],[折旧年份] ,[折旧月份], [补充说明]) VALUES (@资产编号,@折旧方法,@月度折旧额,@折旧年份 ,@折旧月份,@补充说明)";
MyCommand = MyConnection.CreateCommand();
MyCommand.CommandText = MySQL;
MyCommand.Parameters.Add(new SqlParameter("@资产编号", SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@折旧方法", SqlDbType.VarChar));
MyCommand.Parameters.Add(new SqlParameter("@月度折旧额", SqlDbType.Float));
MyCommand.Parameters.Add(new SqlParameter("@折旧年份", SqlDbType.Int));
MyCommand.Parameters.Add(new SqlParameter("@折旧月份", SqlDbType.Int));
MyCommand.Parameters.Add(new SqlParameter("@补充说明", SqlDbType.VarChar));
MyCommand.Parameters["@资产编号"].Value = MyRow[3];
MyCommand.Parameters["@折旧方法"].Value = MyRow[7];
MyCommand.Parameters["@月度折旧额"].Value = MyRow[10];
MyCommand.Parameters["@折旧年份"].Value = MyRow[12];
MyCommand.Parameters["@折旧月份"].Value = MyRow[13];
MyCommand.Parameters["@补充说明"].Value = MyRow[14];
MyCommand.ExecuteNonQuery();
MyCommand.CommandText = "Update 基本档案 Set 累计折旧=累计折旧+" + MyRow[10].ToString() + ",已提月数=已提月数+1 WHERE 资产编号='" + My资产编号 + "'";
MyCommand.ExecuteNonQuery();
}
MySQL = "DELETE FROM 折旧核算表";
MyCommand = new SqlCommand(MySQL, MyConnection);
MyCommand.ExecuteScalar();
this.Page.RegisterStartupScript("msgonlyalert","<Script>alert('"+MyInfo+"');</Script>");
this.GridView1.DataBind();
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -