?? sellgoods.cs
字號:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GoodsReportManage.Stock;
using GoodsReportManage.ItemClass;
using System.Data.SqlClient;
namespace GoodsReportManage.Sell
{
public partial class s : Form
{
public s()
{
InitializeComponent();
}
SqlBaseClass G_SqlClass = new SqlBaseClass();
WinOperationClass G_OperationClass = new WinOperationClass();
int G_Int_status; //保存工具欄按鈕操作狀態
/// <summary>
/// 控制控件狀態
/// </summary>
private void ControlStatus()
{
this.groupBox1.Enabled = !this.groupBox1.Enabled;
this.toolSave.Enabled = !this.toolSave.Enabled;
this.toolAdd.Enabled = !this.toolAdd.Enabled;
this.toolCancel.Enabled = !this.toolCancel.Enabled;
this.toolAmend.Enabled = !this.toolAmend.Enabled;
this.dgvSellInfo.Enabled = !this.dgvSellInfo.Enabled;
}
/// <summary>
/// 在控件中填充選中的DataGridView控件的數據
/// </summary>
private void FillControls()
{
try
{
this.labGoodsID.Text = this.dgvSellInfo[0, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
this.txtHasPay.Text = this.dgvSellInfo[11, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
this.txtNeedPay.Text = this.dgvSellInfo[10, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
this.txtNum.Text = this.dgvSellInfo[4, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
this.txtRemark.Text = this.dgvSellInfo[12, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
this.cbxUnit.Text = this.dgvSellInfo[5, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
this.cbxSellName.Text = this.dgvSellInfo[2, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
this.dtBirthday.Value = Convert.ToDateTime(this.dgvSellInfo[7, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString());
PropertyClass.GetDgvData = this.dgvSellInfo[3, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
PropertyClass.GetGoodsInPrice = this.dgvSellInfo[8, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
PropertyClass.GetSellPrice = this.dgvSellInfo[9, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
PropertyClass.GetStockSpec = this.dgvSellInfo[6, this.dgvSellInfo.CurrentCell.RowIndex].Value.ToString();
}
catch { }
}
/// <summary>
/// 將控件恢復到原始狀態
/// </summary>
private void ClearControls()
{
this.cbxUnit.SelectedIndex = 0;
this.txtGoodsName.Text = "";
this.txtHasPay.Text = "";
this.txtNeedPay.Text = "";
this.txtNum.Text = "";
this.txtGoodsInPrice.Text = "";
this.txtRemark.Text = "";
this.txtSpec.Text = "";
this.txtSellPrice.Text = "";
this.dtBirthday.Value = DateTime.Now;
this.labGoodsID.Text = "";
}
private void SellGoods_Load(object sender, EventArgs e)
{
this.timer1.Start();
string P_Str_cmdtxt = "SELECT SellID,GoodsID as 教材ID,[Name] as 銷售員姓名,GoodsName as 教材名稱";
P_Str_cmdtxt +=",GoodsNum as 銷售數量,GoodsUnit as 教材單位,GoodsSpec as 教材規格,GoodsTime as 銷售時間";
P_Str_cmdtxt += ",GoodsPrice 進貨價格,SellPrice as 銷售價格,NeedPay as 應收金額,HasPay as 實收金額,Remark as 備注";
P_Str_cmdtxt += " FROM v_UserSell";
this.dgvSellInfo.DataSource = G_SqlClass.GetDs(P_Str_cmdtxt).Tables[0];
G_OperationClass.BindComboBox("SELECT * FROM tb_Customer", cbxCustomerName, "Name");
G_OperationClass.BindComboBox("SELECT * FROM tb_Unit", cbxUnit, "UnitName");
G_OperationClass.BindComboBox("SELECT * FROM tb_User",cbxSellName,"Name");
}
private void btnFindGoods_Click(object sender, EventArgs e)
{
StockFind stockfind = new StockFind();
stockfind.StartPosition = FormStartPosition.CenterScreen;
stockfind.ShowDialog();
}
private void toolSave_Click(object sender, EventArgs e)
{
string P_Str_condition, P_Str_cmdtxt;
switch (G_Int_status)
{
case 1:
if (this.cbxSellName.SelectedValue.ToString() != "")
{
if (this.txtGoodsName.Text == "")
{
MessageBox.Show("教材名稱不能為空!", "提示對話框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (this.txtNum.Text == "")
{
MessageBox.Show("教材數量不能為空!", "提示對話框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (this.txtGoodsInPrice.Text == "")
{
MessageBox.Show("教材進價不能為空!", "提示對話框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (this.txtSellPrice.Text == "")
{
MessageBox.Show("銷售價格不能為空!", "提示對話框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (this.txtNeedPay.Text == "")
{
MessageBox.Show("應付金額不能為空!", "提示對話框", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (!G_OperationClass.IsNumeric(this.txtNum.Text) && !G_OperationClass.IsNumeric(this.txtGoodsInPrice.Text)
&& !G_OperationClass.IsNumeric(this.txtHasPay.Text) && !G_OperationClass.IsNumeric(this.txtSellPrice.Text))
{
MessageBox.Show("您輸入的數據格式有誤!", "提示對話框", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
string P_Str_Id = String.Empty;
//檢索數據庫中對應客戶的ID
string P_Str_cmdtxt2 = "SELECT UserID,Name FROM tb_User WHERE Name='" + this.cbxSellName.SelectedValue.ToString() + "'";
SqlDataReader P_dr = G_SqlClass.GetReader(P_Str_cmdtxt2);
P_dr.Read();
if (P_dr.HasRows)
{
P_Str_Id = P_dr["UserID"].ToString();
}
P_dr.Close();
//下面是要執行的SQL語句
P_Str_cmdtxt = "INSERT INTO tb_Sell(SellID,GoodsID,UserID,GoodsName,GoodsNum,GoodsUnit,GoodsTime,GoodsSpec,GoodsPrice,SellPrice";
P_Str_cmdtxt += ",Remark,NeedPay,HasPay,StockID) VALUES('" + this.labGoodsID.Text + "','" + PropertyClass.GetGoodsID + "','" + P_Str_Id + "'";
P_Str_cmdtxt += ",'" + this.txtGoodsName.Text + "','" + this.txtNum.Text + "','" + this.cbxUnit.SelectedValue.ToString() + "'";
P_Str_cmdtxt += ",'" + this.dtBirthday.Value.ToString("yyyy-MM-dd") + "','" + this.txtSpec.Text + "'," + this.txtGoodsInPrice.Text + "";
P_Str_cmdtxt += "," + this.txtSellPrice.Text + ",'" + this.txtRemark.Text + "'";
P_Str_cmdtxt += "," + this.txtNeedPay.Text + "," + this.txtHasPay.Text + ",'" + PropertyClass.GetStockID + "')";
SqlDataReader P_dr2 = G_SqlClass.GetReader("select GoodsID,StockNum from tb_Stock where GoodsID='"
+ PropertyClass.GetGoodsID + "' and StockNum<'" + Convert.ToInt32(txtNum.Text.Trim()) + "'");
P_dr2.Read();
if (P_dr2.HasRows)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -