标题:我的c#+winform+sql server数据库开发
只看楼主
songssong
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-12-18
结帖率:100%
已结贴  问题点数:20 回复次数:26 
我的c#+winform+sql server数据库开发


窗体看上云太简单。这个是用来继承用的。
在这个父窗体中,包含了一个架构。看一下继承得到的窗体。



打印是用ReportViewer2005.微软自家的rdlc报表。
搜索更多相关主题的帖子: 继承 数据库开发 server 微软 
2011-12-18 20:36
songssong
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-12-18
得分:0 
nysong.rar (15.2 KB)

父窗体。
接下来我将从数据库设计,到数据收集,再到数据展现同高手们一同探讨。
2011-12-18 20:42
songssong
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-12-18
得分:0 
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace jinxiaocun
{
    public partial class caigrk : nysong .nysong
    {
        public caigrk()
        {
            co = "Data Source=.; Initial Catalog=jxc;User Id=sa;Pwd=";
            jiegsql = "select spbh 商品编号,spmch 商品名称,dw 单位,shpgg 商品规格,shpchd 商品产地,shl 数量,dj 单价,jine 金额  from cgrkmx where 1=2";
            //cxsql = "select banman 版面,wei 版面位,danjia 单价,0 as 次数,0 应收金额,'         ' 开始期,'' 结束期,shuoming 说明 from shfeije where banman like song_value";
            cxsql = "select spbh 商品编号,spmch 商品名称,dw 单位,shpgg 商品规格,shpchd 商品产地,0 数量,dj 单价,0 金额 from spkfk where spbh like song_value or spmch like song_value or zjm like song_value";
            lxx = "";//打开主表数据辅助查询录入
            djming = "采购入库";
            InitializeComponent();
            toolStripButton4.Visible = false;

            textBox2.Text = DateTime.Now.Date.ToString("yyyy-MM-dd");
            textBox3.Text = "cgrk" + soosn("cgrk", 1).ToString().TrimEnd();//不加1取单据号
            DataSet aaa = new DataSet();
            aaa = songsql_oledb("select ywy 业务员 from ZHIYDOC where zhiw='业务员'", "sso");
            for (int i = 0; i < aaa.Tables["sso"].Rows.Count; i++)
            {
                comboBox1.Items.Add(aaa.Tables["sso"].Rows[i][0]);
            }



            DataSet sop = new DataSet();
            sop = songsql_oledb("select * from cgrkmx where djbh='" + textBox3.Text + "'", "abc");
            if (sop.Tables["abc"].Rows.Count != 0) { textBox3.Text = "cgrk" + soosn("cgrk", 0).ToString().TrimEnd(); }
            song_grid1(jiegsql);
        }

        private void textBox4_DoubleClick(object sender, EventArgs e)
        {
            tttso = 4;
            cxdjtou = "仓库选择";//打开单据头查询
            labelsong.Text  = cxdjtou;
            cxtait("select ckid 仓库代码,ckmch 仓库名称,ckmji 仓库面积,fzr 负责人,dianhua 电话,qita 说明 from ckzl");//查询单据头内容
        }
        public override void grid2_to_djtext(int row)//填单据头
        {
            //MessageBox.Show(dataGridView2.Rows[row ].Cells[1].Value.ToString ());
            if (tttso == 4)
            {
                textBox4.Text = dataGridView2.Rows[row].Cells[1].Value.ToString().TrimEnd() + "(" + dataGridView2.Rows[row].Cells[0].Value.ToString().TrimEnd() + ")";
                panel1.Visible = false;
            }
            if (tttso == 1)
            {
                textBox1.Text = dataGridView2.Rows[row].Cells[1].Value.ToString().TrimEnd() + "(" + dataGridView2.Rows[row].Cells[0].Value.ToString().TrimEnd() + ")";
                panel1.Visible = false;
            }
        }

        private void textBox1_DoubleClick(object sender, EventArgs e)
        {
            tttso = 1;
            cxdjtou = "客户选择";//打开单据头查询
            labelsong.Text = cxdjtou;
            cxtait("select kehuid 客户代码,kehuming 客户名称,dizhi 地址,dianhua 电话,qita 说明 from kehuzl");//查询单据头内容
        }

        public override void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)//计算两列得到第三列
        {//用来定义一列 等于两列的积,或两列的和。
            //MessageBox .Show ( e.RowIndex.ToString ());
            //jijsuan(r);
            jijsuan(e.RowIndex, 5, 6, 7, 1);//*法

            //hejsuan(e.RowIndex, 3, 5, 6, 2);//+法
        }

        public override void songdata() //存入数据库  
        {
            DataSet sop = new DataSet();
            sop = songsql_oledb("select * from cgrkmx where djbh='" + textBox3.Text + "'", "abc");
            if (sop.Tables["abc"].Rows.Count != 0) { MessageBox.Show("当前单据号已存在,如果已打印请新开单据!"); return; }

            SqlConnection conn = new SqlConnection(co);
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM cgrkmx where 1=2", conn);
            SqlCommandBuilder cmdbuilder = new SqlCommandBuilder(adapter);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "spp");
            DataTable dttt = ds.Tables["spp"];
            if (dataGridView1.Rows.Count > 0)
            {
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    if (dataGridView1.Rows[i].Cells[0].Value.ToString() != "" &&
                       dataGridView1.Rows[i].Cells[1].Value.ToString() != "" &&
                       dataGridView1.Rows[i].Cells[2].Value.ToString() != "" &&
                       dataGridView1.Rows[i].Cells[3].Value.ToString() != "" &&
                       dataGridView1.Rows[i].Cells[4].Value.ToString() != "" &&
                       dataGridView1.Rows[i].Cells[5].Value.ToString() != "" &&
                       dataGridView1.Rows[i].Cells[6].Value.ToString() != "" &&
                       dataGridView1.Rows[i].Cells[7].Value.ToString() != "")
                    {
                        //  spbh 商品编号,spmch 商品名称,dw 单位,shpgg 商品规格,shpchd 商品产地,shl 数量,dj 单价,jine 金额                     
                        DataRow newRow = dttt.NewRow();
                        newRow["djbh"] = textBox3.Text;
                        newRow["rq"] = textBox2.Text;// ((int)(i + 1)).ToString();
                        newRow["plh"] = ((int)(i + 1)).ToString();
                        newRow["djbhrqplh"] = textBox3.Text + textBox2.Text + ((int)(i + 1)).ToString();
                        newRow["ywy"] = comboBox1.Text;
                        newRow["kehu"] = textBox3.Text;
                        newRow["spbh"] = dataGridView1.Rows[i].Cells[0].Value;
                        newRow["spmch"] = dataGridView1.Rows[i].Cells[1].Value;
                        newRow["dw"] = dataGridView1.Rows[i].Cells[2].Value;
                        newRow["shpgg"] = dataGridView1.Rows[i].Cells[3].Value;
                        newRow["shpchd"] = dataGridView1.Rows[i].Cells[4].Value;
                        newRow["shl"] = ToDBC(dataGridView1.Rows[i].Cells[5].Value.ToString ());
                        newRow["dj"] = ToDBC(dataGridView1.Rows[i].Cells[6].Value.ToString ());
                        newRow["jine"] = ToDBC(dataGridView1.Rows[i].Cells[7].Value.ToString ());
                        newRow["ywy"] = comboBox1.Text ;
                        newRow["rkck"] = textBox4.Text;
                        newRow["kehu"] = textBox1.Text;
                        dttt.Rows.Add(newRow);
                        adapter.Update(ds, "spp");
                    }
                    else
                    {
                        MessageBox.Show("数据不完整或违反规则不能存盘");
                        return;
                    }
                }
                proc();
                if (DialogResult.OK == MessageBox.Show("存盘完毕,如果未打印新开下一单据请点新开单据,是否打印?", "打印提示!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                {
                    panel3.Visible = true;
                    panel3.Width = this.Width;
                    panel3.Top = toolStrip1.Height;
                    panel3.Left = 0;
                    panel3.Height = this.Height - toolStrip1.Height;

                    toolStripButton1.Visible = false;
                    toolStripButton2.Visible = false;
                    toolStripButton4.Visible = true;
                    toolStripButton3.Visible = false;
                    songprint();
                }
            }
        }
        private void xkdj()//新开单据                 
        {
            DataSet sop = new DataSet();
            sop = songsql_oledb("select * from cgrkmx where djbh='" + textBox3.Text + "'", "abc");
            if (sop.Tables["abc"].Rows.Count == 0) { MessageBox.Show("当前单据尚未存盘,请存盘打印!"); return; }
            dataGridView1.SelectAll();
            foreach (DataGridViewRow r in dataGridView1.SelectedRows)
            {
                if (!r.IsNewRow)
                {
                    dataGridView1.Rows.Remove(r);
                }
            }
            textBox2.Text = DateTime.Now.Date.ToString("yyyy-MM-dd");
            comboBox1.Text = "";
            textBox3.Text = "cgrk" + soosn("cgrk", 0).ToString().TrimEnd();//加1取单据号
            textBox1.Text = "";
            textBox4.Text = "";
            song_grid1(jiegsql);
        }
        private void proc()//存完单据后进行数据库操作
        {
            SqlConnection conn = new SqlConnection(co);
            SqlCommand comm = new SqlCommand();
            // = CommandType.StoredProcedure;
             = CommandType.Text;
            comm.Connection = conn;
             = "insert cgrkhz (rq,djbh,ywy,rkck,kehu,jine) select rq,djbh,ywy,rkck,kehu,sum(jine) jine  from cgrkmx where djbh='" + textBox3.Text + "' group by rq,djbh,ywy,rkck,kehu ; exec cgrkdj '"+ textBox3.Text + "'";
            //SqlParameter sssin = new SqlParameter("@snlx", SqlDbType.VarChar, 30);
            //sssin.Direction = ParameterDirection.Input;
            //sssin.Value = lx;
            //SqlParameter nn = new SqlParameter("@n", SqlDbType.VarChar, 30);
            //nn.Direction = ParameterDirection.Input;
            //nn.Value = n;
            //SqlParameter sss = new SqlParameter("@sn", SqlDbType.VarChar, 30);
            //sss.Direction = ParameterDirection.Output;
            //comm.Parameters.Add(sssin);
            //comm.Parameters.Add(sss);
            //comm.Parameters.Add(nn);
            conn.Open();
            comm.ExecuteNonQuery();
            conn.Close();
            //return sss.Value.ToString();
        }
        private void songprint()                     //
        {

            //开始打印
            djprint xx = new djprint();

            DataTable me = new DataTable("33");
            me.Columns.Add(new DataColumn("商品编号", typeof(string)));
            me.Columns.Add(new DataColumn("商品名称", typeof(string)));
            me.Columns.Add(new DataColumn("单位", typeof(string)));
            me.Columns.Add(new DataColumn("商品规格", typeof(string)));
            me.Columns.Add(new DataColumn("商品产地", typeof(string)));
            //me.Columns.Add(new DataColumn("应收金额", typeof(Single)));
            me.Columns.Add(new DataColumn("数量", typeof(decimal)));
            me.Columns.Add(new DataColumn("单价", typeof(decimal)));
            me.Columns.Add(new DataColumn("金额", typeof(decimal)));


            if (dataGridView1.Rows.Count > 0)
            {
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    DataRow aa = me.NewRow();
                    for (int m = 0; m < me.Columns.Count; m++)
                    {
                        aa[m] = ToDBC (dataGridView1.Rows[i].Cells[m].Value.ToString ());
                    }
                    me.Rows.Add(aa);
                }
                //DataSet mmm = new DataSet();
                //mmm = songsql_oledb("select banman 版面,danjia 单价,wei 版位,shuoming 说明 from shfeije ", "me");
                ReportDataSource rds = new ReportDataSource("djprint_caigrk", me);
                reportViewer1.LocalReport.ReportPath = Application.StartupPath.ToString() + @"\printdj\caigrkdj.rdlc";
                reportViewer1.LocalReport.DataSources.Clear();
                reportViewer1.LocalReport.DataSources.Add(rds);
                ReportParameter[] parameters = new ReportParameter[5];
                parameters[0] = new ReportParameter("para0", textBox2.Text.ToString());
                parameters[1] = new ReportParameter("para1", textBox3.Text.ToString());
                parameters[2] = new ReportParameter("para2", textBox1.Text.ToString());
                parameters[3] = new ReportParameter("para3", comboBox1.Text.ToString());
                parameters[4] = new ReportParameter("para4", textBox4.Text.ToString());
                reportViewer1.LocalReport.SetParameters(parameters);
                reportViewer1.LocalReport.Refresh();
                reportViewer1.RefreshReport();

            }
        }
        public override void reportViewer1_Print(object sender, CancelEventArgs e)//打印时   
        {
            panel3.Visible = false;
            toolStripButton4.Visible = false;
            toolStripButton1.Visible = true;
            toolStripButton2.Visible = true;
            toolStripButton3.Visible = true;
            xkdj();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)//保存按纽
        {
            songdata();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)//打印按纽
        {
            panel3.Visible = true;
            panel3.Width = this.Width;
            panel3.Top = toolStrip1.Height;
            panel3.Left = 0;
            panel3.Height = this.Height - toolStrip1.Height;

            toolStripButton1.Visible = false;
            toolStripButton2.Visible = false;
            toolStripButton3.Visible = false;
            toolStripButton4.Visible = true;
            songprint();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)//返回按纽
        {
            panel3.Visible = false;
            toolStripButton4.Visible = false;
            toolStripButton1.Visible = true;
            toolStripButton2.Visible = true;
            toolStripButton3.Visible = true;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)//新建按纽
        {
            xkdj();
        }


    }
}
2011-12-18 20:44
songssong
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-12-18
得分:0 
这就是一个采购入库单。
2011-12-18 20:47
songssong
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-12-18
得分:0 
看起来代码比较乱。其实也就几个过程。
2011-12-18 20:53
songssong
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-12-18
得分:0 
先来说说数据库方面的东西吧。这可是企业的管理的灵魂。如果是做业务方面的东西sql语句还是要下点功。不难的。看看我写的。
  
CREATE  PROCEDURE song_sn   
@snlx varchar(30),  
@n int,  
@sn varchar(30) output  
  
AS  
declare @tran_point int    --控制事务嵌套   
set @tran_point=@@trancount  --保存事务点   
if @tran_point=0   
 begin tran tran_songsn   
else   
save tran tran_songsn   
---------  
if @n=0  
begin  
update song_djsn set cc=cc+1 where djlx=@snlx  
update song_djsn set sn=str(cc) where djlx=@snlx  
update song_djsn set sn=replace(sn,' ','0') where djlx=@snlx  
select @sn=sn from song_djsn where djlx=@snlx  
if @tran_point=0   
commit tran tran_songsn  
return @sn  
  
end  
else if @n=1  
begin   
update song_djsn set shu=shu where djlx=@snlx  
select @sn=sn from song_djsn where djlx=@snlx  
if @tran_point=0   
commit tran tran_songsn  
return @sn  
end
2011-12-18 21:01
songssong
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-12-18
得分:0 
上面的是取单据号用的。我把单据号放在
2011-12-18 21:04
songssong
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-12-18
得分:0 
没人看。我有点失望。我会坚持写完。
2011-12-18 21:07
yinniannian
Rank: 9Rank: 9Rank: 9
来 自:河北省石家庄
等 级:蜘蛛侠
威 望:2
帖 子:256
专家分:1007
注 册:2011-5-13
得分:20 
不错。顶一下

代做小型软件。
QQ:449795473
2011-12-19 07:45
songssong
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2011-12-18
得分:0 
什么orm 什么什么的我没用过。也许有人说我太落后,或太土,或太初级。不管那么多。接着说。
并发处理,这个很重要的。所有的存储过程我都事务为零时来执行数据库操作。这样简单,不用想那么多。做软件做那么辛苦干什么?
2011-12-19 11:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-358077-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.380462 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved