コード例 #1
0
        private void btn_schedule_Click(object sender, EventArgs e)
        {
            try
            {
                String codestr  = this.txt_codestr.Text.Trim();
                string indexstr = "";
                if (codestr != "")
                {
                    //预排程前进行数据校验,包括通道和品牌设置等
                    ValidationClass vc       = new ValidationClass();
                    Response        response = vc.ValidationSchedule("1");

                    response.IsSuccess = true;


                    btn_schedule.Enabled = false;
                    String[] code = codestr.Substring(1).Split(',');
                    //int len = code.Length;
                    Dictionary <string, List <string> > dic = new Dictionary <string, List <string> >();
                    w_SortStrategy frm = new w_SortStrategy();
                    frm.ShowDialog();
                    if (frm.Index >= 0)
                    {
                        dic = SortStrategy(frm.Index, code);
                    }
                    else
                    {
                        MessageBox.Show("请选择排程策略");
                        return;
                    }
                    if (response.IsSuccess)
                    {
                        DialogResult MsgBoxResult = MessageBox.Show("车组排程顺序为【" + codestr.Substring(1) + "】,是否确定按照该顺序进行预排程?", //对话框的显示内容
                                                                    "提示",                                                    //对话框的标题
                                                                    MessageBoxButtons.YesNo,                                 //定义对话框的按钮,这里定义了YSE和NO两个按钮
                                                                    MessageBoxIcon.Question,                                 //定义对话框内的图表式样,这里是一个黄色三角型内加一个感叹号
                                                                    MessageBoxDefaultButton.Button2);                        //定义对话框的按钮式样
                        if (MsgBoxResult == DialogResult.Yes)
                        {
                            TransactionOptions transactionOption = new TransactionOptions();
                            transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                            using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required, transactionOption))
                            {
                                bool flag = true;
                                foreach (var item in dic)
                                {
                                    List <string> regions = new List <string>();
                                    regions = item.Value;
                                    for (int i = 0; i < regions.Count; i++)
                                    {
                                        panel2.Visible       = true;
                                        label2.Visible       = true;
                                        progressBar1.Visible = true;
                                        progressBar1.Value   = 0;
                                        Application.DoEvents();
                                        if (i == 0)
                                        {
                                            label2.Text = "正在对" + regions[i] + "车组的单条订单数据进行预排程...";
                                        }
                                        var resc = sc.PreScheduleForSingleOrder(regions[i]);
                                        progressBar1.Value = ((i + 1) * 100 / (regions.Count * 2));
                                        progressBar1.Refresh();
                                        String tmpstr = "";
                                        if (resc.IsSuccess)
                                        {
                                            if (i + 1 < regions.Count)
                                            {
                                                tmpstr = "正在对" + regions[i + 1] + "车组单条订单数据进行预排程...";
                                            }
                                            else
                                            {
                                                tmpstr = "";
                                            }
                                            label2.Text = regions[i] + "车组单条订单数据预排程结束..." + tmpstr;
                                            label2.Refresh();
                                            indexstr = indexstr + "," + regions[i];
                                        }
                                        else
                                        {
                                            label2.Text = resc.MessageText;
                                            label2.Refresh();
                                            flag = false;
                                            break;
                                        }
                                    }

                                    for (int i = 0; i < regions.Count; i++)
                                    {
                                        panel2.Visible       = true;
                                        label2.Visible       = true;
                                        progressBar1.Visible = true;
                                        progressBar1.Value   = 0;
                                        Application.DoEvents();
                                        if (i == 0)
                                        {
                                            label2.Text = "正在对" + regions[i] + "车组订单数据进行预排程...";
                                        }
                                        var resc = sc.PreSchedule(regions[i]);
                                        progressBar1.Value = ((regions.Count + i + 1) * 100 / (regions.Count * 2));
                                        progressBar1.Refresh();
                                        String tmpstr = "";
                                        if (resc.IsSuccess)
                                        {
                                            if (i + 1 < regions.Count)
                                            {
                                                tmpstr = "正在对" + regions[i + 1] + "车组订单数据进行预排程...";
                                            }
                                            else
                                            {
                                                tmpstr = "";
                                            }
                                            label2.Text = regions[i] + "车组订单数据预排程结束..." + tmpstr;
                                            label2.Refresh();
                                            indexstr = indexstr + "," + regions[i];
                                        }
                                        else
                                        {
                                            label2.Text = resc.MessageText;
                                            label2.Refresh();
                                            flag = false;
                                            break;
                                        }
                                    }
                                }
                                if (flag)
                                {
                                    tran.Complete();
                                }
                                else
                                {
                                    MessageBox.Show("预排程错误,事务回滚");
                                }
                            }


                            panel2.Visible       = false;
                            label2.Visible       = false;
                            progressBar1.Visible = false;
                            MessageBox.Show("预排程成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        MessageBox.Show(response.MessageText, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("请至少选择一个要预排程的车组!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                panel2.Visible       = false;
                label2.Visible       = false;
                progressBar1.Visible = false;
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                btn_schedule.Enabled = true;
                Bind();
            }


            //try
            //{
            //    String codestr = this.txt_codestr.Text.Trim();
            //    string indexstr = "";
            //    if (codestr != "")
            //    {
            //        //预排程前进行数据校验,包括通道和品牌设置等
            //        ValidationClass vc = new ValidationClass();
            //        Response response = vc.ValidationSchedule("1");
            //        if (response.IsSuccess)
            //        {
            //            DialogResult MsgBoxResult = MessageBox.Show("车组排程顺序为【" + codestr.Substring(1) + "】,是否确定按照该顺序进行预排程?",//对话框的显示内容
            //                                                               "提示",//对话框的标题
            //                                                               MessageBoxButtons.YesNo,//定义对话框的按钮,这里定义了YSE和NO两个按钮
            //                                                               MessageBoxIcon.Question,//定义对话框内的图表式样,这里是一个黄色三角型内加一个感叹号
            //                                                               MessageBoxDefaultButton.Button2);//定义对话框的按钮式样
            //            if (MsgBoxResult == DialogResult.Yes)
            //            {
            //                btn_schedule.Enabled = false;
            //                String[] code = codestr.Substring(1).Split(',');
            //                int len = code.Length;

            //                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] + "车组的单条订单数据进行预排程...";
            //                    var resc = sc.PreScheduleForSingleOrder(code[i]);
            //                    progressBar1.Value = ((i + 1) * 100 / (len * 2));
            //                    progressBar1.Refresh();
            //                    String tmpstr = "";
            //                    if (resc.IsSuccess)
            //                    {
            //                        if (i + 1 < len) tmpstr = "正在对" + code[i + 1] + "车组单条订单数据进行预排程...";
            //                        else tmpstr = "";
            //                        label2.Text = code[i] + "车组单条订单数据预排程结束..." + tmpstr;
            //                        label2.Refresh();
            //                        indexstr = indexstr + "," + code[i];
            //                    }
            //                    else
            //                    {
            //                        label2.Text = resc.MessageText;
            //                        label2.Refresh();
            //                        break;
            //                    }
            //                }
            //                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] + "车组订单数据进行预排程...";
            //                    var resc = sc.PreSchedule(code[i]);
            //                    progressBar1.Value = ((len + i + 1) * 100 / (len * 2));
            //                    progressBar1.Refresh();
            //                    String tmpstr = "";
            //                    if (resc.IsSuccess)
            //                    {
            //                        if (i + 1 < len) tmpstr = "正在对" + code[i + 1] + "车组订单数据进行预排程...";
            //                        else tmpstr = "";
            //                        label2.Text = code[i] + "车组订单数据预排程结束..." + tmpstr;
            //                        label2.Refresh();
            //                        indexstr = indexstr + "," + code[i];
            //                    }
            //                    else
            //                    {
            //                        label2.Text = resc.MessageText;
            //                        label2.Refresh();
            //                        break;
            //                    }
            //                }
            //                panel2.Visible = false;
            //                label2.Visible = false;
            //                progressBar1.Visible = false;
            //                MessageBox.Show("预排程成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //            }
            //        }
            //        else
            //        {
            //            MessageBox.Show(response.MessageText, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        }
            //    }
            //    else
            //    {
            //        MessageBox.Show("请至少选择一个要预排程的车组!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    }

            //}
            //catch (Exception ex)
            //{
            //    panel2.Visible = false;
            //    label2.Visible = false;
            //    progressBar1.Visible = false;
            //    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            //finally
            //{
            //    btn_schedule.Enabled = true;
            //    Bind();
            //}
        }