www.pudn.com > FORU(SMS).rar > SMS_GoodsOut.cs


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.Data.SqlClient; 
 
namespace FORU_SMS_ 
{ 
    public partial class SMS_GoodsOut : Form 
    { 
        BaseClass.DataConn Dconn = new FORU_SMS_.BaseClass.DataConn(); 
        BaseClass.DataClass Dclass = new FORU_SMS_.BaseClass.DataClass(); 
        BaseClass.GoodsOut Gout = new FORU_SMS_.BaseClass.GoodsOut(); 
        SqlDataReader sqlRead; 
        public SMS_GoodsOut() 
        { 
            InitializeComponent(); 
        } 
 
        private void SMS_GoodsOut_Load(object sender, EventArgs e) 
        { 
            dgvOSManage.Controls.Add(hScrollBar1); 
            Dclass.BindComboBox("select StoreName from SMS_Store", "SMS_Store", "StoreName", cboxSName); 
            Dclass.BindComboBox("select DepName from SMS_DepartMent", "SMS_DepartMent","DepName", cboxGDep); 
            Dclass.BindComboBox("select GoodsName from SMS_Goods", "SMS_Goods", "GoodsName", cboxGName); 
            DataSet ds = Dclass.GetDataSet("select GoodsID AS 货物编号, GoodsName AS 货物名称, SupName AS 仓库名称," 
            + "SpecName AS 货物规格, UnitName AS 计量单位,GoodsNum AS 出库数量, GoodsPrice AS 货物单价, GoodsAPrice AS 总金额," 
            + "GoodsTime AS 出库日期,GoodsPeople AS 经手人, UpGoodsPeople AS 提货人,GoodsDep As 提货单位, GoodsRemarks AS 备注 from SMS_GoodsOut", "SMS_GoodsOut"); 
            dgvOSManage.DataSource = ds.Tables["SMS_GoodsOut"]; 
        } 
 
        private void cboxGName_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            sqlRead = Dclass.GetRead("select GoodsID,GoodsNum,UnitName,SpecName,GoodsPrice,GoodsAPrice,GoodsPeople from SMS_Goods where GoodsName='" + this.cboxGName.Text.Trim() + "'"); 
            //and SupName='" + this.cboxSName.Text.Trim() + "' 
            if (sqlRead.Read()) 
            { 
                this.cboxGUnit.Text = sqlRead["UnitName"].ToString().Trim(); 
                this.txtOSGNum.Text = sqlRead["GoodsNum"].ToString().Trim(); 
                this.cboxGSpec.Text = sqlRead["SpecName"].ToString().Trim(); 
                this.txtGOPrice.Text = sqlRead["GoodsPrice"].ToString().Trim(); 
                this.txtGSPrice.Text = sqlRead["GoodsAPrice"].ToString().Trim(); 
                this.txtHPeople.Text = sqlRead["GoodsPeople"].ToString().Trim(); 
                this.GoodsID.Text = sqlRead["GoodsID"].ToString().Trim(); 
            } 
            sqlRead.Close(); 
        } 
 
        private void button2_Click(object sender, EventArgs e) 
        { 
            dgvOSManage.Refresh(); 
            DataSet ds = Dclass.GetDataSet("select GoodsID AS 货物编号, GoodsName AS 货物名称, SupName AS 仓库名称," 
            + "SpecName AS 货物规格, UnitName AS 计量单位,GoodsNum AS 出库数量, GoodsPrice AS 货物单价, GoodsAPrice AS 总金额," 
            + "GoodsTime AS 出库日期,GoodsPeople AS 经手人, UpGoodsPeople AS 提货人,GoodsDep As 提货单位, GoodsRemarks AS 备注 from SMS_GoodsOut", "SMS_GoodsOut"); 
            dgvOSManage.DataSource = ds.Tables[0]; 
        } 
 
        private void btnAdd_Click(object sender, EventArgs e) 
        { 
            sqlRead = Dclass.GetRead("select GoodsID,GoodsNum,UnitName,SpecName,GoodsPrice,GoodsAPrice,GoodsPeople from SMS_Goods where GoodsName='" + this.cboxGName.Text.Trim() + "'"); 
            if (sqlRead.Read()) 
            { 
                if (Convert.ToInt32(sqlRead["GoodsNum"].ToString().Trim()) < 1) 
                { 
                    MessageBox.Show("库存不足!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                } 
                else 
                { 
                    if (this.cboxSName.Text == "") 
                    { 
                        MessageBox.Show("仓库名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        cboxSName.Focus(); 
                    } 
                    else if (this.cboxGName.Text == "") 
                    { 
                        MessageBox.Show("产品名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        cboxGName.Focus(); 
                    } 
                    else if (this.cboxGSpec.Text == "") 
                    { 
                        MessageBox.Show("产品规格不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        cboxGSpec.Focus(); 
                    } 
                    else if (this.txtOSGNum.Text == "") 
                    { 
                        MessageBox.Show("产品数量不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        txtOSGNum.Focus(); 
                    } 
                    else if (Convert.ToInt32(this.txtOSGNum.Text) == 0) 
                    { 
                        MessageBox.Show("产品数量不能为0!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        txtOSGNum.Text = ""; 
                        txtOSGNum.Focus(); 
                    } 
                    else if (Convert.ToInt32(this.txtOSGNum.Text) > Convert.ToInt32(sqlRead["GoodsNum"].ToString().Trim())) 
                    { 
                        MessageBox.Show("没有足够的货物!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        this.txtOSGNum.Text = ""; 
                        this.txtOSGNum.Focus(); 
                    } 
                    else if (this.txtOSPeople.Text == "") 
                    { 
                        MessageBox.Show("提取人不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        txtOSPeople.Focus(); 
                    } 
                    else if (this.cboxGDep.Text == "") 
                    { 
                        MessageBox.Show("提取单位不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                        cboxGUnit.Focus(); 
                    } 
                    else 
                    { 
                        Gout._GoodsID = this.GoodsID.Text.ToString().Trim(); 
                        Gout._GoodsName = this.cboxGName.Text.ToString().Trim(); 
                        Gout._SpecName = this.cboxGSpec.Text.ToString().Trim(); 
                        Gout._SupName = this.cboxSName.Text.ToString().Trim(); 
                        Gout._UnitName = this.cboxGUnit.Text.ToString().Trim(); 
                        Gout._UpGoodsPeople = this.txtOSPeople.Text.ToString().Trim(); 
                        Gout._GoodsPeople = this.txtHPeople.Text.ToString().Trim(); 
                        Gout._GoodsDep = this.cboxGDep.Text.ToString().Trim(); 
                        Gout._GoodsNum = int.Parse(this.txtOSGNum.Text.Trim()); 
                        Gout._GoodsPrice = double.Parse(this.txtGOPrice.Text.Trim()); 
                        Gout._GoodsAPrice = double.Parse(this.txtGSPrice.Text.Trim()); 
                        Gout._GoodsRemarks = this.txtOSRemark.Text.ToString().Trim(); 
                        Gout.OutGoods(); 
 
                        dgvOSManage.Refresh(); 
                        DataSet ds = Dclass.GetDataSet("select GoodsID AS 货物编号, GoodsName AS 货物名称, SupName AS 仓库名称," 
                        + "SpecName AS 货物规格, UnitName AS 计量单位,GoodsNum AS 出库数量, GoodsPrice AS 货物单价, GoodsAPrice AS 总金额," 
                        + "GoodsTime AS 出库日期,GoodsPeople AS 经手人, UpGoodsPeople AS 提货人,GoodsDep As 提货单位, GoodsRemarks AS 备注 from SMS_GoodsOut", "SMS_GoodsOut"); 
                        dgvOSManage.DataSource = ds.Tables[0]; 
 
                        MessageBox.Show("提交成功!"); 
 
                        Dclass.BindComboBox("select GoodsName from SMS_Goods", "SMS_Goods", "GoodsName", cboxGName); 
                        //cboxGName.Items.Clear(); 
                        //DataTable dt = Dclass.GetDataTable("select GoodsName from SMS_Goods"); 
                        //for (int i = 0; i < dt.Rows.Count; i++) 
                        //{ 
                        //    this.cboxGName.Items.Add(dt.Rows[i][0].ToString().Trim()); 
                        //} 
 
                        this.cboxGSpec.Text = ""; 
                        this.cboxGUnit.Text = ""; 
                        this.txtOSGNum.Text = ""; 
                        this.txtGOPrice.Text = ""; 
                        this.txtGSPrice.Text = ""; 
                        this.txtHPeople.Text = ""; 
                        this.txtOSRemark.Text = ""; 
                    } 
                } 
            } 
            sqlRead.Close(); 
 
        } 
 
        private void btnDel_Click(object sender, EventArgs e) 
        { 
            if (this.dgvOSManage.SelectedRows.Count == 0) 
            { 
                MessageBox.Show("请选择一个操作项!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
            } 
            else 
            { 
                try 
                { 
                    Dclass.ExecuteSql("delete from SMS_GoodsOut where GoodsID='" + dgvOSManage.SelectedRows[0].Cells[0].Value.ToString() + "'"); 
                    SMS_GoodsOut_Load(sender, e); 
                    MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                } 
                catch (Exception exc) 
                { 
                    MessageBox.Show(exc.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
                } 
                    //MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                    //dgvOSManage.Refresh(); 
                    //DataSet ds = Dclass.GetDataSet("select GoodsID AS 货物编号, GoodsName AS 货物名称, SupName AS 仓库名称," 
                    //+ "SpecName AS 货物规格, UnitName AS 计量单位,GoodsNum AS 出库数量, GoodsPrice AS 货物单价, GoodsAPrice AS 总金额," 
                    //+ "GoodsTime AS 出库日期,GoodsPeople AS 经手人, UpGoodsPeople AS 提货人,GoodsDep As 提货单位, GoodsRemarks AS 备注 from SMS_GoodsOut", "SMS_GoodsOut"); 
                    //dgvOSManage.DataSource = ds.Tables[0]; 
            } 
        } 
 
 
        private void btnExit_Click(object sender, EventArgs e) 
        { 
            this.Close(); 
        } 
 
        private void txtOSGNum_KeyPress(object sender, KeyPressEventArgs e) 
        { 
            if (e.KeyChar <= 57 && e.KeyChar >= 48 || e.KeyChar == 46 || e.KeyChar == 8) 
            { 
                e.Handled = false; 
            } 
            else 
            { 
                e.Handled = true; 
            } 
        } 
 
    } 
}