示例#1
0
        private void btn_recieve_Click(object sender, EventArgs e)
        {
            decimal maxSyncseq = 0;

            try
            {
                maxSyncseq = sc.GetSyncseqFromOrderTable().Content;
                String codestr = this.txt_codestr.Text.Trim();
                btn_recieve.Enabled = false;
                if (codestr != "")
                {
                    String[]           code = codestr.Substring(1).Split(',');
                    int                len = code.Length, sucCount = 0;
                    string             indexstr          = "";
                    TransactionOptions transactionOption = new TransactionOptions();
                    transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                    using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required, transactionOption))
                    {
                        bool flag = true;
                        for (int i = 0; i < len; i++)
                        {
                            panel2.Visible       = true;
                            label2.Visible       = true;
                            progressBar1.Visible = true;
                            progressBar1.Value   = 0;
                            Application.DoEvents();
                            if (i == 0)
                            {
                                label2.Text = "正在接收" + code[i] + "车组订单数据...";
                            }
                            DateTime time = DateTime.Parse(datePick.Value.ToString());
                            var      re   = sc.ReceiveSaleOrderToOrder(time, code[i], maxSyncseq);//接收数据

                            progressBar1.Value = ((i + 1) * 100 / len);
                            progressBar1.Refresh();
                            String tmpstr = "";

                            if (re.IsSuccess)
                            {
                                if (i + 1 < len)
                                {
                                    tmpstr = "正在接收" + code[i + 1] + "车组订单数据...";
                                }
                                else
                                {
                                    tmpstr = "";
                                }
                                label2.Text = code[i] + "车组订单数据接收完毕..." + tmpstr;
                                label2.Refresh();
                                indexstr = indexstr + "," + code[i];
                                sucCount++;
                            }
                            else
                            {
                                label2.Text = re.MessageText;
                                label2.Refresh();
                                MessageBox.Show(re.MessageText);
                                flag = false;
                                break;
                            }
                        }
                        if (flag)
                        {
                            tran.Complete();
                        }
                        else
                        {
                            MessageBox.Show("数据接收错误,事务回滚");
                        }
                    }


                    //根据批次maxSyncseq验证是否有新品牌和客户,提示定性新品牌并设置条烟转换比例
                    Response response  = new Response();
                    String   resultMsg = "";
                    //验证是否有新品牌
                    response = sc.ValidNewItem(maxSyncseq);
                    if (!response.IsSuccess)
                    {
                        resultMsg = resultMsg + "品牌验证:" + response.MessageText;
                        //MessageBox.Show(response.MessageText, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    //验证是否有新客户

                    /*response = sc.ValidNewCustomer(maxSyncseq);
                     *  if (!response.IsSuccess)
                     *  {
                     *      resultMsg = "\r\n" + resultMsg + "零售户验证:" + response.MessageText;
                     *      //MessageBox.Show(response.MessageText, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     *  }*/
                    //验证订单数量
                    response = sc.ValiOrderNum(maxSyncseq, this.datePick.Value);
                    if (!response.IsSuccess)
                    {
                        resultMsg = "\r\n" + resultMsg + "订单数验证:" + response.MessageText;
                        //MessageBox.Show(response.MessageText, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    if (!"".Equals(resultMsg))
                    {
                        MessageBox.Show(resultMsg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    Bind();

                    MessageBox.Show(sucCount + "个车组的订单数据接收成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("请至少选择一个要接收订单的车组!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                this.btn_recieve.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("订单接收异常" + ex.Message);
            }
            finally
            {
                panel2.Visible       = false;
                label2.Visible       = false;
                progressBar1.Visible = false;
            }
        }