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();
}
}
}