⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xskdform.cs

📁 医药连锁软件源码,设计说明 需求说明请联系:dighonor@163.com
💻 CS
📖 第 1 页 / 共 2 页
字号:
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 xlsb
{
    public partial class xskdForm : Form
    {
        public static int flag = 0;//打开查询器时的条件标志
        public static string saletaff = "";//设置职员编号的公共变量,供查询窗口赋值,属过渡变量
        public static xskdForm pCurrentWin = null;
        private DataSet ds = new DataSet();
        private DataSet mxsj = new DataSet();
        private SqlDataAdapter da = new SqlDataAdapter();
        public DataTable dt = new DataTable();
        private SqlConnection myConnection = new SqlConnection("Data Source=" + main.servername + ";Initial Catalog=" + main.dbname + ";Persist Security Info=True;User ID=" + main.saname + ";Password=" + main.pass);
        //用来存放销售单的中输入数据的最大号
       private int maxno,i = 0;
        public xskdForm()
        {
            InitializeComponent();
            pCurrentWin = this;
        }
        private System.Data.DataSet dbconn(string strSql)//连结主表记录过程
        {
            if (myConnection.State.ToString() == "Closed")
                myConnection.Open();
            da = new SqlDataAdapter(strSql, myConnection);
            ds.Reset(); 
            da.Fill(ds);
            if (myConnection.State.ToString() == "Open")
                myConnection.Close();
            return ds;
        }
        private System.Data.SqlClient.SqlCommand addrecord(string strSql)//追加或删除数据库记录过程
        {
            myConnection.Open();
            SqlCommand addrec = new SqlCommand(strSql, myConnection);
            addrec.ExecuteNonQuery();
            if (myConnection.State.ToString() == "Open")
                myConnection.Close();

            return addrec;
        }
        private System.Data.DataSet mxdata(bool addorquery)//子表数据查询
        {
          if (myConnection.State.ToString() == "Closed")
            myConnection.Open();
            string strsql = "SELECT dbo.SALPROFM.MD_SaleProofNo, dbo.SALPROFM.MD_Index,dbo.SALPROFM.MD_GoodsNo, dbo.SALPROFM.MD_GoodsProofNo,dbo.SALPROFM.MD_GoodsUnit, dbo.SALPROFM.MD_Quantity,dbo.SALPROFM.MD_Price, dbo.SALPROFM.MD_Money, dbo.SALPROFM.MD_TaxPrice, dbo.SALPROFM.MD_Tax,dbo.SALPROFM.MD_Discount, dbo.SALPROFM.MD_Profit,dbo.SALPROFM.MD_InPrice, dbo.SALPROFM.MD_LeftQuantity,dbo.SALPROFM.MD_ChangeRate, dbo.SALPROFM.Md_Reserve,dbo.STOREALL.MD_GoodsName, dbo.STOREALL.MD_Unit,dbo.STOREALL.MD_GoodsSource, dbo.STOREALL.MD_GoodsStyle FROM dbo.SALPROFM LEFT OUTER JOIN  dbo.STOREALL ON dbo.SALPROFM.MD_GoodsNo = dbo.STOREALL.MD_GoodsNo where dbo.SALPROFM.MD_SaleProofNo='" + label20.Text.Trim() + "'";
            da = new SqlDataAdapter(strsql, myConnection);
            DataSet mxsj = new DataSet();
            if (addorquery == true)//如果状态为新增时,绑定数据表
            {
                dt = new DataTable("SALPROFM");
                mxsj.Tables.Add(dt);
                DataColumn col1 = dt.Columns.Add("MD_SaleProofNo", typeof(string));
                DataColumn col2 = dt.Columns.Add("MD_Index", typeof(int));
                DataColumn col3 = dt.Columns.Add("MD_GoodsNo", typeof(string));
                DataColumn col4 = dt.Columns.Add("MD_GoodsProofNo", typeof(string));
                DataColumn col5 = dt.Columns.Add("MD_GoodsUnit", typeof(string));
                DataColumn col6 = dt.Columns.Add("MD_Quantity", typeof(decimal));
                DataColumn col7 = dt.Columns.Add("MD_Price", typeof(decimal));
                DataColumn col8 = dt.Columns.Add("MD_Money", typeof(decimal));
                DataColumn col9 = dt.Columns.Add("MD_TaxPrice", typeof(decimal));
                DataColumn col10 = dt.Columns.Add("MD_Tax", typeof(decimal));
                DataColumn col11 = dt.Columns.Add("MD_Discount", typeof(decimal));
                DataColumn col12 = dt.Columns.Add("MD_Profit", typeof(string));
                DataColumn col14 = dt.Columns.Add("MD_LeftQuantity", typeof(decimal));
                DataColumn col15 = dt.Columns.Add("MD_ChangeRate", typeof(decimal));
                DataColumn col16 = dt.Columns.Add("MD_GoodsName", typeof(string));
                DataColumn col17 = dt.Columns.Add("MD_GoodsSource", typeof(string));
                DataColumn col18 = dt.Columns.Add("MD_GoodsStyle", typeof(string));
                DataColumn col19 = dt.Columns.Add("MD_InPrice", typeof(decimal));
                da.Fill(mxsj);
                dtShow.AutoGenerateColumns = false;
                dtShow.DataSource = mxsj.Tables["SALPROFM"].DefaultView;
            }
            else
            {
                da.Fill(mxsj);
                dtShow.AutoGenerateColumns = false;
                dtShow.DataSource = mxsj.Tables[0].DefaultView;
            }
            if (myConnection.State.ToString() == "Open")
                myConnection.Close();

            return mxsj;
        }
        private void toolStripButton12_Click(object sender, EventArgs e)//关闭窗口
        {
            this.Close();
        }

        private void textBox2_MouseDoubleClick(object sender, MouseEventArgs e)  //按客户号打开查询器
        {
            if (textBox2.Text.Trim() == "")
            {
                flag = 1;
                ListKH KH = new ListKH();
                KH.Show();

            }

        }

        private void textBox2_TextChanged(object sender, EventArgs e)//设置客户编号为空时时,客户名称也清空;
        {
            if (textBox2.Text.Trim() == "")
                textBox3.Text = "";
        }

       private void xskdForm_Load(object sender, EventArgs e)//激活窗口时,直接打开新增销售单功能
        {
            toolStripButton5_Click(null, null);
           
        }

        private void textBox6_MouseDoubleClick(object sender, MouseEventArgs e) //按业务员打开查询器
        {
            if (textBox6.Text.Trim() == "")
            {
                flag = 2;
                ListKH KH = new ListKH();
                KH.Show();

            }
        }

        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)//按客户名打开查询器
        {
            if (dtShow.CurrentCell.ColumnIndex == 0 || dtShow.CurrentCell.ColumnIndex == 1)
            {
                flag = 3;
                ListKH KH = new ListKH();
                KH.Show();
            }

        }

        private void toolStripButton5_Click(object sender, EventArgs e)//新增销售单时功能初始化窗口上的所有控件数据
        {
            
            if (toolStripButton5.Text == "&A增加")
            {
                 
                dtShow.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect;
                textBox1.Text = DateTime.Today.ToShortDateString(); ;
                textBox2.Text = "";
                textBox4.Text = "";
                textBox6.Text = "";
                textBox7.Text = "";
                comboBox1.Text = "";
                comboBox2.Text = "";
                textBox11.Text = "";
                textBox13.Text = "";
                textBox12.Text = "";
                textBox15.Text = "";
                textBox10.Text = "";
                string strsql = "SELECT [VALUE], LEN FROM SysID WHERE (DBF_NAME = 'salprofs')";
                dbconn(strsql);
                string dh = "0000000" + ds.Tables[0].Rows[0]["value"].ToString();
                maxno = Convert.ToInt16(ds.Tables[0].Rows[0]["value"].ToString()) + 1;
                label20.Text = "XS" + dh.Substring((dh.Length - Convert.ToInt16(ds.Tables[0].Rows[0]["len"].ToString())), Convert.ToInt16(ds.Tables[0].Rows[0]["len"].ToString()));
                strsql = "SELECT MD_StoreLoc FROM STOREGOO GROUP BY MD_StoreLoc";
                dbconn(strsql);
                for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                {
                    comboBox2.Items.Add(ds.Tables[0].Rows[j]["MD_StoreLoc"].ToString());
                }
                saveandlist(false);
                mxdata(true);

            }
            else//保存数据过程
            {
                
                if (dtShow.CurrentRow == null)//如果dataGridView为空时中断保存
                    return;
                if ((dtShow.CurrentRow.Index + 1) == dtShow.RowCount)//最后一行为空数据时清除此行
                {
                    if (dt.Rows[dtShow.CurrentRow.Index]["MD_GoodsUnit"].ToString().Trim() == "")
                        dt.Rows[dtShow.RowCount - 1].Delete();
                } else
                if ((dtShow.CurrentRow.Index +2) == dtShow.RowCount)
                    if (dt.Rows[dtShow.CurrentRow.Index + 1]["MD_GoodsUnit"].ToString().Trim() == "")
                        dt.Rows[dt.Rows.Count-1].Delete();
                this.BindingContext[this.dtShow.DataSource].EndCurrentEdit();
                if (textBox11.Text.ToString().Trim()=="")
                    textBox11.Text="销售["+dt.Rows[0]["MD_GoodsName"].ToString()+"]等给["+textBox3.Text.ToString().Trim()+"]"+textBox6.Text;
                string strsql= "";
                strsql = "insert into SALPROFS (MD_SaleProofNo,MD_InvoiceNo, MD_SaleStaff, MD_Department,MD_SaleDate, MD_ClientNo,MD_StoreLoc,MD_TaxRadio, MD_PayStyle,  MD_PayPeriod,MD_TotalSaleMoney, MD_TotalTaxMoney,MD_TotalMoney, MD_TotalProfit,MD_Staff,MD_Remark,MD_CheckFlag,MD_BackUpFlag,MD_ProofFlag,Md_InvoiceMoney) VALUES ( '";
                strsql += label20.Text.ToString().Trim() + "','";
                strsql += textBox4.Text.ToString().Trim() + "','";
                strsql += saletaff .ToString() + "','";
                strsql += textBox7.Text.ToString() + "','";
                strsql += textBox1.Text.ToString() + "','";
                strsql += textBox2.Text.ToString() + "','";
                strsql += comboBox2.Text.ToString() + "','";
                strsql += textBox9.Text.ToString() + "','";
                strsql += comboBox1.Text.ToString() + "','";
                strsql += textBox5.Text.ToString() + "','";
                strsql += textBox13.Text.ToString() + "','";
                strsql += textBox12.Text.ToString() + "','";
                strsql += textBox15.Text.ToString() + "',";
                strsql +=  "0,'";
                strsql += textBox14.Text.ToString() + "','";
                strsql += textBox11.Text.ToString() + "',";
                strsql +=  "'N',";
                strsql +=  "0,";
                strsql +=  "0,";
                strsql +=  "0)";
                addrecord(strsql);
                strsql = "UPDATE SysID SET [VALUE] =" +maxno+" WHERE (DBF_NAME = 'salprofs')";//更新最大单据号标志
                addrecord(strsql);//更新主表
                for (int i = 0; i < dtShow.RowCount; i++)
                {
                       strsql = "insert into SALPROFM (MD_SaleProofNo,MD_GoodsNo, MD_Index, MD_GoodsProofNo,MD_GoodsUnit, MD_Quantity,MD_Price,MD_TaxPrice, MD_Money,  MD_Tax,MD_Discount, MD_Profit,MD_InPrice, MD_LeftQuantity,MD_ChangeRate) VALUES ( '";
                        strsql += dt.Rows[i]["MD_SaleProofNo"].ToString() + "','";
                        strsql += dt.Rows[i]["MD_GoodsNo"].ToString() + "',";
                        strsql += dt.Rows[i]["MD_Index"].ToString() + ",'";
                        strsql += dt.Rows[i]["MD_GoodsProofNo"].ToString() + "','";
                        strsql += dt.Rows[i]["MD_GoodsUnit"].ToString() + "',";
                        strsql += dt.Rows[i]["MD_Quantity"].ToString() + ",";
                        strsql += dt.Rows[i]["MD_Price"].ToString() + ",";
                        strsql += dt.Rows[i]["MD_TaxPrice"].ToString() + ",";
                        strsql += dt.Rows[i]["MD_Money"].ToString() + ",";
                        strsql += dt.Rows[i]["MD_Tax"].ToString() + ",";
                        strsql += dt.Rows[i]["MD_Discount"].ToString() + ",";
                        strsql += dt.Rows[i]["MD_Profit"].ToString() + ",";
                        strsql += dt.Rows[i]["MD_InPrice"].ToString() + ",";
                        strsql += dt.Rows[i]["MD_LeftQuantity"].ToString() + ",";
                        strsql += dt.Rows[i]["MD_ChangeRate"].ToString()+")";
                        addrecord(strsql);//追加从表记录
                 }
                 saveandlist(true);
                  strsql = "SELECT dbo.SALPROFS.MD_SaleProofNo, dbo.SALPROFS.MD_InvoiceNo, dbo.SALPROFS.MD_SaleStaff, dbo.SALPROFS.MD_Department, dbo.SALPROFS.MD_SaleDate, dbo.SALPROFS.MD_ClientNo,dbo.SALPROFS.MD_StoreLoc, dbo.SALPROFS.MD_TaxRadio,dbo.SALPROFS.MD_PayStyle, dbo.SALPROFS.MD_PayPeriod,dbo.SALPROFS.MD_TotalSaleMoney, dbo.SALPROFS.MD_TotalTaxMoney,dbo.SALPROFS.MD_TotalMoney, dbo.SALPROFS.MD_TotalProfit,dbo.SALPROFS.MD_Staff, dbo.SALPROFS.MD_Remark, dbo.SALPROFS.MD_CheckFlag, dbo.SALPROFS.MD_BackUpFlag,dbo.SALPROFS.MD_ProofFlag, dbo.SALPROFS.Md_InvoiceMoney,dbo.CLIENT.MD_ClientName, dbo.STAFF.MD_StaffName FROM dbo.SALPROFS INNER JOIN dbo.STAFF ON  dbo.SALPROFS.MD_SaleStaff = dbo.STAFF.MD_StaffNo LEFT OUTER JOIN dbo.CLIENT ON dbo.SALPROFS.MD_ClientNo = dbo.CLIENT.MD_ClientNo WHERE (SALPROFS.MD_CheckFlag = 'N')";
                 dbconn(strsql);
                 filldata(ds.Tables[0].Rows.Count-1);
                 
                 mxdata( false);
            }
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -