?? salereduceform.aspx.cs
字號:
?//文件名:SaleReduceForm.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 SaleManage_SaleReduceForm : System.Web.UI.Page
{
private static DataTable MyGoodsTable = new DataTable();
private static int MyID = 0;
protected void Page_Load(object sender, EventArgs e)
{
string MyForbidString = Session["MyForbid"].ToString();
if (MyForbidString.IndexOf("D2") > 1)
{
Server.Transfer("~/SystemManage/AllErrorHelp.aspx");
}
this.Button5.OnClientClick = "return confirm('請檢查銷售退貨商品信息是否正確,一旦新增就無法修改,是否繼續?')";
this.Button3.OnClientClick = "return confirm('請檢查銷售退貨單信息是否正確,一旦保存就無法修改,是否繼續?')";
}
protected void Button1_Click(object sender, EventArgs e)
{//新增銷售退貨單
String MySQLConnectionString = ConfigurationManager.ConnectionStrings["MySaleDBConnectionString"].ConnectionString;
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
string MySQL = "Select * From 銷售信息 Where 銷售單號='" + this.TextBox1.Text + "'";
SqlCommand MyCommand = new SqlCommand(MySQL, MyConnection);
if (MyCommand.ExecuteScalar() != null)
{
this.Page.RegisterStartupScript("msgOnlyAlert", "<script>alert('銷售退貨單號已經存在!')</script>");
this.TextBox1.Text = "";
}
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
//創建無連接的數據表
DataColumn[] MyKey = new DataColumn[1];
MyGoodsTable = new DataTable("商品銷售退貨明細表");
DataColumn MyColumn = new DataColumn();
MyColumn.DataType = System.Type.GetType("System.Int16");
MyColumn.ColumnName = "自編號";
MyGoodsTable.Columns.Add(MyColumn);
MyKey[0] = MyColumn;
MyGoodsTable.PrimaryKey = MyKey;
MyGoodsTable.Columns.Add("商品編號", System.Type.GetType("System.String"));
MyGoodsTable.Columns.Add("商品名稱", System.Type.GetType("System.String"));
MyGoodsTable.Columns.Add("規格型號", System.Type.GetType("System.String"));
MyGoodsTable.Columns.Add("計量單位", System.Type.GetType("System.String"));
MyGoodsTable.Columns.Add("商品單價", System.Type.GetType("System.Double"));
MyGoodsTable.Columns.Add("退貨數量", System.Type.GetType("System.Double"));
MyGoodsTable.Columns.Add("退貨金額", System.Type.GetType("System.Double"));
MyGoodsTable.Columns.Add("補充說明", System.Type.GetType("System.String"));
this.GridView2.DataSource = MyGoodsTable;
this.GridView2.DataBind();
MyID = 0;
this.TextBox2.Text = "0";
}
protected void Button3_Click(object sender, EventArgs e)
{//保存銷售退貨單
if (this.TextBox2.Text.Length < 2)
return;
String MySQLConnectionString = ConfigurationManager.ConnectionStrings["MySaleDBConnectionString"].ConnectionString;
string MySQL = "INSERT INTO 銷售信息(銷售單號,客戶名稱,應收金額,實收金額,收款方式,經辦人員,出庫日期,補充說明)VALUES('";
MySQL += this.TextBox1.Text + "','";
MySQL += this.DropDownList1.SelectedValue.ToString() + "','";
MySQL += "-" + this.TextBox2.Text + "','";
MySQL += "-" + this.TextBox3.Text + "','";
MySQL += this.DropDownList2.SelectedValue.ToString() + "','";
MySQL += this.TextBox4.Text + "','";
MySQL += this.TextBox5.Text + "','";
MySQL += this.TextBox6.Text + "');";
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
SqlCommand MyCommand = MyConnection.CreateCommand();
MyCommand.CommandText = MySQL;
MyCommand.ExecuteNonQuery();
foreach (DataRow MyRow in MyGoodsTable.Rows)
{
MySQL = "INSERT INTO 銷售明細(銷售單號,商品編號,商品名稱,規格型號,計量單位,商品單價,銷售數量,銷售金額,補充說明) VALUES('";
MySQL += this.TextBox1.Text + "','";
MySQL += MyRow[1].ToString() + "','";
MySQL += MyRow[2].ToString() + "','";
MySQL += MyRow[3].ToString() + "','";
MySQL += MyRow[4].ToString() + "','";
MySQL += MyRow[5].ToString() + "','";
MySQL += "-" + MyRow[6].ToString() + "','";
MySQL += "-" + MyRow[7].ToString() + "','";
MySQL += MyRow[8].ToString() + "');";
MySQL += "Update 商品信息 SET 累計銷售量=累計銷售量-" + MyRow[6].ToString() + " WHERE 商品編號='" + MyRow[1].ToString() + "';";
MyCommand.CommandText = MySQL;
MyCommand.ExecuteNonQuery();
}
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
this.TextBox1.Text = "";
MyGoodsTable.Rows.Clear();
this.GridView2.DataSource = MyGoodsTable;
this.GridView2.DataBind();
MyID = 0;
this.TextBox2.Text = "0";
}
protected void Button5_Click(object sender, EventArgs e)
{//新增退貨商品
if (this.TextBox13.Text.Length > 1)
{
MyID = MyID + 1;
DataRow MyRow = MyGoodsTable.NewRow();
MyRow[0] = MyID;
MyRow["商品編號"] = this.TextBox7.Text;
MyRow["商品名稱"] = this.TextBox8.Text;
MyRow["規格型號"] = this.TextBox9.Text;
MyRow["計量單位"] = this.TextBox10.Text;
MyRow["商品單價"] = this.TextBox11.Text;
MyRow["退貨數量"] = this.TextBox12.Text;
MyRow["退貨金額"] = this.TextBox13.Text;
MyRow["補充說明"] = this.TextBox15.Text;
MyGoodsTable.Rows.Add(MyRow);
this.GridView2.DataSource = MyGoodsTable;
this.GridView2.DataBind();
Double My應付金額 = Convert.ToDouble(this.TextBox2.Text);
My應付金額 += Convert.ToDouble(this.TextBox13.Text);
this.TextBox2.Text = My應付金額.ToString();
this.TextBox13.Text = "";
}
}
protected void TextBox12_TextChanged(object sender, EventArgs e)
{//計算退貨商品金額
double MyPrice = Convert.ToDouble(this.TextBox11.Text);
double MyNumber = Convert.ToDouble(this.TextBox12.Text);
double MyAmount = MyPrice * MyNumber;
this.TextBox13.Text = MyAmount.ToString();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{//顯示選擇的商品信息
if (this.TextBox1.Text.Length > 1)
{
this.TextBox7.Text = this.GridView1.SelectedRow.Cells[1].Text.ToString();
this.TextBox8.Text = this.GridView1.SelectedRow.Cells[2].Text.ToString();
this.TextBox9.Text = this.GridView1.SelectedRow.Cells[3].Text.ToString();
this.TextBox10.Text = this.GridView1.SelectedRow.Cells[4].Text.ToString();
this.TextBox11.Text = this.GridView1.SelectedRow.Cells[5].Text.ToString();
}
}
public String MyPrint銷售退貨單號
{//設置要傳遞到打印頁的數據
get
{
return this.TextBox1.Text;
}
}
public String MyPrint客戶名稱
{//設置要傳遞到打印頁的數據
get
{
return this.DropDownList1.SelectedValue.ToString();
}
}
public String MyPrint應付金額
{//設置要傳遞到打印頁的數據
get
{
return this.TextBox2.Text;
}
}
public String MyPrint實付金額
{//設置要傳遞到打印頁的數據
get
{
return this.TextBox3.Text;
}
}
public String MyPrint付款方式
{//設置要傳遞到打印頁的數據
get
{
return this.DropDownList2.SelectedValue.ToString();
}
}
public String MyPrint經辦人員
{//設置要傳遞到打印頁的數據
get
{
return this.TextBox4.Text;
}
}
public String MyPrint入庫日期
{//設置要傳遞到打印頁的數據
get
{
return this.TextBox5.Text;
}
}
public String MyPrint補充說明
{//設置要傳遞到打印頁的數據
get
{
return this.TextBox6.Text;
}
}
public DataTable MyPrintDataTable
{//設置要傳遞到打印頁的數據
get
{
return MyGoodsTable;
}
}
protected void Button2_Click(object sender, EventArgs e)
{//打印商品銷售退貨單
Server.Transfer("~/SaleManage/SaleReducePrint.aspx");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -