test

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Substrate2Pda.Substrate2Pda_ws;
using System.Runtime.InteropServices;


namespace Substrate2Pda
{
    public partial class Form1 : Form
    {  
       
        public int RowCount = 0;
        public double Qnty;
        public string Belnr;
        public string IssueNum;
        public string BarCode;

 

        public Form1()
        {
           
            InitializeComponent();
   

        }


        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {

                    string[] sArray = BarCode.Split(',');
                    int i = sArray.Length;
                    switch (i)
                    {
                        case 2:
                            textBox1.Text = sArray[0];
                            textBox2.Text = null;
                            textBox3.Text = null;
                            string Zmblnr = sArray[0];
                            Belnr = sArray[0];
                            IssueNum = sArray[1];
                            return_info sap_rfc = new return_info();
                            Service1 ws_1 = new Service1();
                            sap_rfc = ws_1.Substrate2Pda(Zmblnr);
                            RowCount = sap_rfc.ds_info.Tables[0].Rows.Count;
                            if (sap_rfc.pe == "FAIL")
                            {
                                MessageBox.Show("無法連接SAP");
                            }
                            else if (sap_rfc.pe == "SUCCESS")
                            {

                                DataGridTableStyle myDataGridStyle = null;
                                GridColumnStylesCollection myDataGridColStyle = null;
                                dataGrid1.DataSource = sap_rfc.ds_info.Tables[0];//设置数据源
                                myDataGridStyle = new DataGridTableStyle();
                                myDataGridStyle.MappingName = sap_rfc.ds_info.Tables[0].TableName;
                                dataGrid1.TableStyles.Clear(); // 先清除格式
                                dataGrid1.TableStyles.Add(myDataGridStyle);//加载格式
                                // 设置dataGrid 列的宽度
                                myDataGridColStyle = dataGrid1.TableStyles[0].GridColumnStyles;
                                myDataGridColStyle[0].Width = 28;
                                myDataGridColStyle[1].Width = 118;
                                myDataGridColStyle[2].Width = 50;
                                myDataGridColStyle[3].Width = 200;
                                myDataGridColStyle[4].Width = 50;

 

                            }
                            break;
                        case 6:
                            string Zmatnr = sArray[1].Remove(0, 2);
                            string Zmenge = sArray[4].Remove(0, 1);
                            textBox3.Text = Zmatnr;


                            int Id = -1;
                            for (int j = 0; j < RowCount; j++)
                            {
                                if (dataGrid1[j, 1].ToString().Equals(isNumberic(Zmatnr)))
                                {
                                    textBox3.Text = isNumberic(Zmatnr);
                                    Id = j;
                                    if (textBox2.Focused)
                                    {
                                        textBox2.Text = BarCode;
                                    }
                                    else
                                    {
                                        textBox2.Text = BarCode;
                                        textBox2.Focus();
                                        keybd_event(13, 0, 0, 0);//模擬鍵盤按下ENTER鍵
                                    }


                                    break;
                                }

                            }
                            if (RowCount != 0)
                            /*{
                                textBox3.Text = null;
                                MessageBox.Show("請先掃描單據條碼");
                            }
                            else*/
                            {
                                if (Id == -1)
                                {
                                    textBox2.Text = null;
                                    textBox3.Text = null;
                                    MessageBox.Show("不在單據內");

                                }
                            }

                            break;
                        default:
                            break;


                    }
                }
            }
            catch
            {
                MessageBox.Show("請先掃描單據條碼");
                textBox2.Text = null;
                textBox3.Text = null;
            }
        }

  
        protected string isNumberic(string message)
        {
            try
            {

                long result = long.Parse(message);
                string matnr = "00" + message;
                return matnr;
            }
            catch
            {
                string matnr = message;
                return matnr;
            }

 

        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {  
            if (e.KeyCode == Keys.Enter)
            {
                try
                {

                    string[] sArray = textBox2.Text.Split(',');
                    int m = sArray.Length;
                    switch (m)
                    {
                        case 1:

                            for (int i = 0; i < RowCount; i++)
                            {
                                if (dataGrid1[i, 1].ToString().Equals(textBox3.Text.Trim()))
                                {

                                    double x = double.Parse(dataGrid1[i, 4].ToString()) - double.Parse(textBox2.Text.ToString().Trim());
                                    if (x < 0)
                                    {
                                        MessageBox.Show("數量多於未處理量");
                                        break;
                                    }
                                    dataGrid1[i, 4] = x;

                                    break;
                                }

                            }


                            break;

                        case 6:
                            textBox2.Text = sArray[4].Remove(0, 1);

                            break;

                        default:
                            //    MessageBox.Show("請處理結束后再處理下一筆資料");
                            //   textBox2.Text = null;
                            break;

                    }
                }
                catch
                {
                    if (textBox2.Text == "" && textBox3.Text == "")
                    {
                    }
                    else
                    {
                        MessageBox.Show("請先掃描單據條碼");
                        textBox2.Text = null;
                        textBox3.Text = null;
                    }
                }

            }
        }

        private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < RowCount; i++)
            {
                if ((double.Parse(dataGrid1[i, 4].ToString()) == 0))
                {
                    if (dataGrid1[i, 0].Equals("OK"))
                    {  
                    }
                    else
                    {
                      
                        dataGrid1[i, 0] = "OK";
                    }
                }
                 

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                int sum_ok = 0;
                for (int i = 0; i < RowCount; i++)
                {

                    Qnty += double.Parse(dataGrid1[i, 2].ToString());

                    if (dataGrid1[i, 0].ToString().Equals("OK"))
                    {

                        sum_ok += 1;
                    }
                    else
                    {
                        MessageBox.Show("全部OK才可進行下一步");
                        break;
                    }

                }
                if (sum_ok == RowCount)
                {
                    Form2 f2 = new Form2(IssueNum, Belnr, Qnty);
                    dataGrid1.DataSource = null;
                    textBox1.Text = null;
                    textBox2.Text = null;
                    textBox3.Text = null;
                    f2.Show();

                }
            }
            catch
            {
                textBox2.Focus();
            }
        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            string x = null;
            x = e.KeyChar.ToString();
            BarCode += e.KeyChar;
            string[] zArray = BarCode.Split('\r');
            int n = zArray.Length;
            BarCode = zArray[n-1];

        }

        private void button1_Click(object sender, EventArgs e)
        {

            dataGrid1.DataSource = null;
            textBox1.Text = null;
            textBox2.Text = null;
            textBox3.Text = null;
            textBox2.Focus();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
           

        }

        [DllImport("Coredll.dll", EntryPoint = "keybd_event")]
        public static extern void keybd_event(
            byte bVk,
            byte bScan,
            int dwFlags,
            int dwExtraInfo
        );

        private void dataGrid1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                int index = dataGrid1.CurrentRowIndex;


                DialogResult MsgResult = MessageBox.Show("確認修改?", "OK/CANCEL", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (MsgResult == DialogResult.OK)
                {
                    dataGrid1[index, 0] = "OK";
                }
                else if (MsgResult == DialogResult.Cancel)
                {

                }
            }
            catch
            {
            }

        }

 

 

    }

 

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值