Example #1
0
        /// <summary>
        /// 保存任务按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            int saveflag = 0;

            string now_taskId = "";

            now_taskId = txtTaskId.Text;

            if (!now_taskId.Trim().Equals(""))
            {
                //2015年10月18日修改,增加保存试验任务时判断该任务编号是否存在已运行的样品(t_test_allocation表trunc(f_sample_status/10)>1)
                //如果存在,不可进行保存操作
                ProxyBllTEST_ALLOCATION bllTestAllocation = new ProxyBllTEST_ALLOCATION();
                DataSet dsTestSample = bllTestAllocation.GetList(" trunc(F_SAMPLE_STATUS/10)>1 AND F_TEST_TASK_ID='" + now_taskId + "' ");
                if (dsTestSample != null && dsTestSample.Tables[0].Rows.Count != 0)
                {
                    MessageBox.Show("任务编号:" + now_taskId + "的试验任务中存在已运行的样品,不可进行保存操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //判断该试验任务编号的信息是否处于“已提交”状态
                //如果当前保存任务为“已提交”状态任务,执行保存操作后,提示任务状态将修改为“未提交”状态。需要重新执行提交操作。
                ProxyBllTESINFODB bllTestDB = new ProxyBllTESINFODB();
                DataSet           dsTaskId  = bllTestDB.GetList(" F_TEST_TASK_ID='" + now_taskId + "' ");
                if (dsTaskId != null && dsTaskId.Tables[0].Rows.Count != 0)
                {
                    DialogResult dialogResult = XtraMessageBox.Show("任务编号:" + now_taskId + "的试验任务已提交,是否重新保存任务信息?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (dialogResult == DialogResult.No)
                    {
                        return;
                    }
                    else
                    {
                        bllTestDB.DropWhere(" F_TEST_TASK_ID='" + now_taskId + "' ");
                    }
                }
                //判断试验基础信息必填项是否已填写
                //试验基础信息必填项已填写,保存该组数据到T_TEST_INFO表中
                if (judgeTestBaseInfo())
                {
                    BllTEST_INFO blltest_info = new BllTEST_INFO();

                    //判断该任务编号在数据库中是否存在,如果存在进行修改处理,否则进行新增操作
                    DataSet dsTaskCount   = blltest_info.GetTaskCount(now_taskId);
                    int     temptaskCount = -1;

                    if (dsTaskCount != null)
                    {
                        if (dsTaskCount.Tables[0].Rows.Count > 0)
                        {
                            temptaskCount = Convert.ToInt16(dsTaskCount.Tables[0].Rows[0][0].ToString());
                        }
                    }
                    if (temptaskCount == 0)  //新增操作
                    {
                        try
                        {
                            //将试验任务数据写入Model类中
                            CreateOrUpdateTestInfo(1);
                            blltest_info.Add(_mdlTestInfo);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("任务编号:" + now_taskId + "的试验基础信息新增保存错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else  //修改操作
                    {
                        try
                        {
                            //将试验任务数据写入Model类中
                            CreateOrUpdateTestInfo(2);
                            blltest_info.Update(_mdlTestInfo);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("任务编号:" + now_taskId + "的试验基础信息修改保存错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    saveflag = saveflag + 1;
                }

                //2015年10月18日修改--判断该任务是否可修改样品,如果可以,执行保存,如不可以,不需执行保存样品的操作
                if (gcSampleInfoList.Enabled)
                {
                    //判断试验样品信息是否有数据行,各数据行的数据是否有效
                    if (judgeTestSampleInfo())
                    {
                        //试验样品信息各数据行的数据有效,保存该组数据到T_TEST_SAMPLE_INFO表中
                        ProxyBllTEST_SAMPLE_INFO bllTestSampleInfo = new ProxyBllTEST_SAMPLE_INFO();

                        //删除该任务编号的样品数据
                        bllTestSampleInfo.DropByTaskId(now_taskId);

                        for (int i = 0; i < _TestSampleTable.Rows.Count; i++)
                        {
                            var modelTestSampleInfo = new ModelTEST_SAMPLE_INFO();
                            modelTestSampleInfo.F_TEST_TASK_ID     = now_taskId;
                            modelTestSampleInfo.F_SAMPLE_NUM       = Convert.ToInt16(_TestSampleTable.Rows[i]["F_SAMPLE_NUM"].ToString());
                            modelTestSampleInfo.F_SAMPLE_GROUP_NUM = _TestSampleTable.Rows[i]["F_SAMPLE_GROUP_NUM"].ToString();
                            modelTestSampleInfo.F_SAMPLE_MEMO      = _TestSampleTable.Rows[i]["F_SAMPLE_MEMO"].ToString();
                            modelTestSampleInfo.F_CREATE_TIME      = DateTime.Now;
                            modelTestSampleInfo.F_OPERATOR_ID      = AppGlobal.GUserId;
                            modelTestSampleInfo.F_OPERATIONTIME    = DateTime.Now;
                            modelTestSampleInfo.F_DEL = 0;

                            bllTestSampleInfo.Add(modelTestSampleInfo);
                        }

                        //生成样品编号,并写入T_TEST_ALLOCATION表中,写入任务编号F_TEST_TASK_ID、样品编号F_TEST_SAMPLE_ID字段
                        //运行状态F_SAMPLE_STATUS值为-1,状态为未分配

                        //删除该任务编号的样品分配信息数据
                        string dropWhere = "";
                        dropWhere = " F_TEST_TASK_ID='" + now_taskId + "' ";
                        bllTestAllocation.DropWhere(dropWhere);

                        //生成任务编号now_taskId的样品编号信息,并写入T_TEST_ALLOCATION
                        for (int i = 0; i < _TestSampleTable.Rows.Count; i++)
                        {
                            var modelTestAllocation = new ModelTEST_ALLOCATION();

                            int    temp_sample_num = Convert.ToInt16(_TestSampleTable.Rows[i]["F_SAMPLE_NUM"].ToString());
                            string temp_group_num  = _TestSampleTable.Rows[i]["F_SAMPLE_GROUP_NUM"].ToString();
                            for (int k = 1; k <= temp_sample_num; k++)
                            {
                                modelTestAllocation.F_TEST_TASK_ID = now_taskId;

                                //以%2f的形式显示
                                if (k < 10)
                                {
                                    modelTestAllocation.F_TEST_SAMPLE_ID = temp_group_num + "-0" + k.ToString();
                                }
                                else
                                {
                                    modelTestAllocation.F_TEST_SAMPLE_ID = temp_group_num + "-" + k.ToString();
                                }
                                //样品编码,试验样品待分配试验通道,状态值为11
                                modelTestAllocation.F_SAMPLE_STATUS = 11;
                                modelTestAllocation.F_CREATE_TIME   = DateTime.Now;
                                modelTestAllocation.F_OPERATOR_ID   = AppGlobal.GUserId;
                                modelTestAllocation.F_OPERATIONTIME = DateTime.Now;
                                modelTestAllocation.F_DEL           = 0;
                                bllTestAllocation.Add_KHD(modelTestAllocation);
                            }
                        }

                        saveflag = saveflag + 10;
                    }
                }

                //判断试验参数数据填写的值是否有效
                if (judgeTestCommParInfo())
                {
                    //试验参数数据填写值有效,保存
                    ProxyBllTEST_PAR_VALUE_KHD bllTestParValue = new ProxyBllTEST_PAR_VALUE_KHD();
                    //删除该任务编号的试验开始命令参数值
                    bllTestParValue.DropByTaskId(now_taskId);

                    for (int i = 0; i < _TestCommStartPar.Rows.Count; i++)
                    {
                        var ModelTEST_PAR_VALUE_KHD = new ModelTEST_PAR_VALUE_KHD();
                        ModelTEST_PAR_VALUE_KHD.F_TASK_ID = now_taskId;
                        //程序代码:在客户端表中备用,均填写为000
                        ModelTEST_PAR_VALUE_KHD.F_PROGRAM_CODE  = "000";
                        ModelTEST_PAR_VALUE_KHD.F_SENDPAR_NAME  = _TestCommStartPar.Rows[i]["F_SENDPAR_NAME"].ToString();
                        ModelTEST_PAR_VALUE_KHD.F_SENDPAR_VALUE = _TestCommStartPar.Rows[i]["F_SENDPAR_VALUE"].ToString();
                        //ModelTEST_PAR_VALUE_KHD.F_SENDPAR_UNIT = _TestCommStartPar.Rows[i]["F_PAR_UNIT"].ToString();
                        ModelTEST_PAR_VALUE_KHD.F_SENDORDER     = Convert.ToInt16(_TestCommStartPar.Rows[i]["colSENDORDER"].ToString());
                        ModelTEST_PAR_VALUE_KHD.F_CREATE_TIME   = DateTime.Now;
                        ModelTEST_PAR_VALUE_KHD.F_OPERATOR_ID   = AppGlobal.GUserId;
                        ModelTEST_PAR_VALUE_KHD.F_OPERATIONTIME = DateTime.Now;
                        ModelTEST_PAR_VALUE_KHD.F_DEL           = 0;

                        bllTestParValue.Add(ModelTEST_PAR_VALUE_KHD);
                    }
                    saveflag = saveflag + 100;
                }
                //根据saveflag的标志信息
                if (saveflag == 111) //试验基础信息、试验样品信息、试验参数信息均保存完成
                {
                    MessageBox.Show("任务编号:" + now_taskId + "的试验基础信息、试验样品信息、试验参数信息保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (saveflag == 110)//试验样品信息、试验参数信息均保存完成
                {
                    MessageBox.Show("任务编号:" + now_taskId + "的试验样品信息、试验参数信息保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (saveflag == 101)//试验基础信息、试验参数信息均保存完成
                {
                    MessageBox.Show("任务编号:" + now_taskId + "的试验基础信息、试验参数信息保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (saveflag == 11) //试验基础信息、试验样品信息保存完成
                {
                    MessageBox.Show("任务编号:" + now_taskId + "的试验基础信息、试验样品信息保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (saveflag == 100) //试验参数信息保存完成
                {
                    MessageBox.Show("任务编号:" + now_taskId + "的试验参数信息保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (saveflag == 10) //试验样品信息保存完成
                {
                    MessageBox.Show("任务编号:" + now_taskId + "的试验样品信息保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (saveflag == 1) //试验基础信息保存完成
                {
                    MessageBox.Show("任务编号:" + now_taskId + "的试验基础信息保存完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                if (saveflag != 0)
                {
                    initData();
                    BindGridview();
                    string tempstr = "";;
                    for (int i = 0; i < lstTasklist.ItemCount; i++)
                    {
                        tempstr = lstTasklist.Items[i].ToString();
                        if (tempstr.Substring(0, tempstr.IndexOf("_")).Equals(now_taskId))
                        {
                            lstTasklist.SelectedIndex = i;
                            break;;
                        }
                    }
                }
            }
        }