Ejemplo n.º 1
0
        private void BtnNumber_Click(object sender, EventArgs e)
        {
            Button          btn = (Button)sender;
            PassToStockEdit ors;

            switch (btn.Name)
            {
            case "Delete":
                try
                {
                    SqlConnection conn   = sqlcon.getcon("");
                    string        strsql = "delete from BR_PassToStock where ID='" + WPHbROWDGV.Rows[WPHbROWDGV.CurrentCell.RowIndex].Cells["ID"].Value.ToString() + "'";
                    conn.Open();
                    SqlCommand sqlcom = new SqlCommand(strsql, conn);
                    sqlcom.ExecuteNonQuery();
                    conn.Close();
                    sqlcom.Dispose();
                    MessageBox.Show("已删除!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                catch
                {
                    MessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                break;

            case "Edit":
                if (WPHbROWDGV.Rows.Count > 0)
                {
                    ors = new PassToStockEdit(WPHbROWDGV.Rows[WPHbROWDGV.CurrentCell.RowIndex].Cells["ID"].Value.ToString(), "BR_PassToStock");
                    ors.ShowDialog();
                }
                break;

            case "Excel":
                if (WPHbROWDGV.Rows.Count > 0)
                {
                    //建立Excel对象
                    Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                    excel.Application.Workbooks.Add(true);
                    //生成字段名称
                    for (int i = 0; i < WPHbROWDGV.ColumnCount; i++)
                    {
                        excel.Cells[1, i + 1] = WPHbROWDGV.Columns[i].HeaderText;
                    }        //填充数据
                    for (int i = 0; i < WPHbROWDGV.RowCount; i++)
                    {
                        for (int j = 0; j < WPHbROWDGV.ColumnCount; j++)
                        {
                            if (WPHbROWDGV[j, i].Value == typeof(string))
                            {
                                excel.Cells[i + 2, j + 1] = "" + WPHbROWDGV[i, j].Value.ToString();
                            }
                            else
                            {
                                excel.Cells[i + 2, j + 1] = WPHbROWDGV[j, i].Value.ToString();
                            }
                        }
                    }
                    excel.Visible = true;
                }
                else
                {
                    MessageBox.Show("没有你要导的数据!!!");
                }
                break;

            case "Pring":     //数据参数新增
                if (WPHbROWDGV.Rows.Count > 0)
                {
                    grproLib.GridppReport Report = new grproLib.GridppReport();
                    DataTable             dt     = new DataTable();
                    SqlConnection         conn   = sqlcon.getcon("");
                    string strsql = " select BR_PassToStock.Cade,Cadedate,m_Factory.title files,Ordercade,BarCode,item_no as Item,S_COLOR as Color,CO_CODE as Code,m_product.photo," +
                                    "m_SizeDetails.cade as Sizecade,m_SizeDetails.[name] as Sizename,khdw,m_SizeDetails.Name as Size,Qty as Nomber,m_ProductSub.pid,username " +
                                    "from BR_PassToStock " +
                                    "left join m_Factory on m_Factory.id=BR_PassToStock.FID " +
                                    "left join m_product on m_product.id=BR_PassToStock.pid " +
                                    "left join m_ProductSub on m_ProductSub.id=BR_PassToStock.colourid " +
                                    "left join m_SizeDetails on m_SizeDetails.id=BR_PassToStock.sdid where BarCode='" + WPHbROWDGV[4, WPHbROWDGV.CurrentCell.RowIndex].Value.ToString() +
                                    "' and BR_PassToStock.Cade='" + WPHbROWDGV[0, WPHbROWDGV.CurrentCell.RowIndex].Value.ToString() + "'";
                    SqlDataAdapter sqlDaper = new SqlDataAdapter(strsql, conn);
                    DataSet        ds       = new DataSet();
                    try
                    {
                        conn.Open();
                        sqlDaper.Fill(ds);
                        conn.Close();

                        try
                        {
                            //下载打印图片
                            string strimageurl             = "http://120.43.209.230:8082/" + ds.Tables[0].Rows[0]["photo"].ToString();
                            System.Net.WebClient webclient = new System.Net.WebClient();
                            webclient.DownloadFile(strimageurl, @"D:\迈途\ZXCPTP.jpg");
                        }
                        catch (Exception ex)
                        {
                            if (File.Exists(@"D:\迈途\ZXCPTP.jpg"))    //判断文件是不是存在
                            {
                                File.Delete(@"D:\迈途\ZXCPTP.jpg");    //如果存在则删除
                            }
                            Console.WriteLine(ex.Message);
                        }

                        Report.LoadFromFile(@rwos().ToString());
                        Report.ConnectionString = sqlcon.XMLIP();
                        Report.QuerySQL         = " select BR_PassToStock.Cade,Cadedate,m_Factory.title files,Ordercade,BarCode,item_no as Item,S_COLOR as Color,CO_CODE as Code,m_product.photo," +
                                                  "m_SizeDetails.cade as Sizecade,m_SizeDetails.[name] as Sizename,khdw,m_SizeDetails.Name as Size,Qty as Nomber,m_ProductSub.pid,username " +
                                                  "from BR_PassToStock " +
                                                  "left join m_Factory on m_Factory.id=BR_PassToStock.FID " +
                                                  "left join m_product on m_product.id=BR_PassToStock.pid " +
                                                  "left join m_ProductSub on m_ProductSub.id=BR_PassToStock.colourid " +
                                                  "left join m_SizeDetails on m_SizeDetails.id=BR_PassToStock.sdid where BarCode='" + WPHbROWDGV[4, WPHbROWDGV.CurrentCell.RowIndex].Value.ToString() +
                                                  "' and BR_PassToStock.Cade='" + WPHbROWDGV[0, WPHbROWDGV.CurrentCell.RowIndex].Value.ToString() + "'";
                        //Report.Print(false);
                        DialogResult result = MessageBox.Show("“是”直接打印,“否”打印预览", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                        if (result == DialogResult.Yes)
                        {
                            Report.Print(false);
                        }
                        else
                        {
                            Report.PrintPreview(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("没有你要打印的数据!!");
                }
                break;
            }
        }
Ejemplo n.º 2
0
        private void BtnNumber_Click(object sender, EventArgs e)
        {
            Button          btn = (Button)sender;
            PassToStockEdit ors;

            switch (btn.Name)
            {
            case "Delete":
                try
                {
                    SqlConnection conn   = sqlcon.getcon("");
                    string        strsql = "delete from BR_PassToStock where ID='" + WPHbROWDGV.Rows[WPHbROWDGV.CurrentCell.RowIndex].Cells["ID"].Value.ToString() + "'";
                    conn.Open();
                    SqlCommand sqlcom = new SqlCommand(strsql, conn);
                    sqlcom.ExecuteNonQuery();
                    conn.Close();
                    sqlcom.Dispose();
                    MessageBox.Show("已删除!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                catch
                {
                    MessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                break;

            case "Edit":
                if (WPHbROWDGV.Rows.Count > 0)
                {
                    ors = new PassToStockEdit(WPHbROWDGV.Rows[WPHbROWDGV.CurrentCell.RowIndex].Cells["ID"].Value.ToString(), "BR_PassToStockReturn");
                    ors.ShowDialog();
                }
                break;

            case "Excel":
                if (WPHbROWDGV.Rows.Count > 0)
                {
                    //建立Excel对象
                    Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                    excel.Application.Workbooks.Add(true);
                    //生成字段名称
                    for (int i = 0; i < WPHbROWDGV.ColumnCount; i++)
                    {
                        excel.Cells[1, i + 1] = WPHbROWDGV.Columns[i].HeaderText;
                    }        //填充数据
                    for (int i = 0; i < WPHbROWDGV.RowCount; i++)
                    {
                        for (int j = 0; j < WPHbROWDGV.ColumnCount; j++)
                        {
                            if (WPHbROWDGV[j, i].Value == typeof(string))
                            {
                                excel.Cells[i + 2, j + 1] = "" + WPHbROWDGV[i, j].Value.ToString();
                            }
                            else
                            {
                                excel.Cells[i + 2, j + 1] = WPHbROWDGV[j, i].Value.ToString();
                            }
                        }
                    }
                    excel.Visible = true;
                }
                else
                {
                    MessageBox.Show("没有你要导的数据!!!");
                }
                break;
            }
        }