/// <summary>
        /// 新增一条记录
        /// </summary>
        /// <param name="qcRecord">质检实体</param>
        /// <returns></returns>
        public static bool InsertOneQCRecord(WaterTestConfigureSet qcRecord)
        {
            bool rbool = true;

            using (DCQUALITYDataContext db = new DCQUALITYDataContext())
            {
                try
                {
                    db.WaterTestConfigureSet.InsertOnSubmit(qcRecord);
                    db.SubmitChanges();
                    rbool = true;
                }
                catch
                {
                    rbool = false;
                }
                finally { db.Connection.Close(); }
            }
            return(rbool);
        }
        private void bind(WaterTestConfigureSet w)
        {
            List <TextBox> tbxList = new List <TextBox>();//包数和针数的txetBox集合

            foreach (TabPage item in tabControl1.TabPages)
            {
                //通过第几次检测找到对应的TabPage
                if (item.Tag != null && item.Tag.ToString() == w.WaterTestConfigureSet_frequency.ToString())
                {
                    DataTable dt = LinQBaseDao.Query("select  TestItems_NAME from TestItems where  TestItems_ID= " + w.WaterTestConfigureSet_TestItems_TestItems_ID).Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        foreach (Control gpx in item.Controls)
                        {
                            //检测项目
                            if (gpx.Text == dt.Rows[0][0].ToString())
                            {
                                //找到groupBox下所有RadioButton
                                List <RadioButton> rbtnList = new List <RadioButton>();
                                foreach (Control rbtn in gpx.Controls)
                                {
                                    if (rbtn is RadioButton)
                                    {
                                        rbtnList.Add((RadioButton)rbtn);
                                    }
                                }


                                RadioButton rbtnProject = null;
                                string      rbtnTxt     = "";

                                switch (w.WaterTestConfigureSet_Project)
                                {
                                case 1:
                                    rbtnTxt = "方案一";

                                    break;

                                case 2:
                                    rbtnTxt = "方案二";
                                    break;

                                case 3:
                                    rbtnTxt = "方案三";
                                    break;

                                default:
                                    break;
                                }
                                foreach (RadioButton rb in rbtnList)
                                {
                                    if (rb.Text == rbtnTxt)
                                    {
                                        rbtnProject = rb;
                                    }
                                }

                                rbtnProject.Checked = true;

                                foreach (Control tbx in gpx.Controls)
                                {
                                    if (tbx.Tag != null && tbx.Tag.ToString() == rbtnProject.Name)
                                    {
                                        //先添加到集合 最后再赋值
                                        tbxList.Add((TextBox)tbx);
                                    }
                                }
                            }
                        }
                    }
                }
                if (tbxList.Count > 0)
                {
                    if (tbxList.Count == 1)
                    {
                        tbxList[0].Text = w.WaterTestConfigureSet_NeedleCount.ToString();
                    }
                    else
                    {
                        tbxList[0].Text = w.WaterTestConfigureSet_PackCount.ToString();
                        tbxList[1].Text = w.WaterTestConfigureSet_NeedleCount.ToString();
                    }
                }
            }
        }
        private int addTestSet(Control ctr)
        {
            //循环groupbox内控件,找到tag=groupbox名称的RadioButton
            int WaterTestConfigureSet_Project = 0;

            foreach (Control item in ctr.Controls)
            {
                if (item.Tag != null && item.Tag.ToString() == ctr.Name)
                {
                    RadioButton r = (RadioButton)item;


                    //找到选中的RadioButton
                    if (r.Checked == true)
                    {
                        if (r.Text == "方案一")
                        {
                            WaterTestConfigureSet_Project = 1;
                        }
                        if (r.Text == "方案二")
                        {
                            WaterTestConfigureSet_Project = 2;
                        }
                        if (r.Text == "方案三")
                        {
                            WaterTestConfigureSet_Project = 3;
                        }
                        //循环控件,找到找到tag=RadioButton名称的textBox
                        tbxList = new List <TextBox>();
                        foreach (Control txtItem in ctr.Controls)
                        {
                            if (txtItem.Tag != null && txtItem.Tag.ToString() == r.Name)
                            {
                                tbxList.Add((TextBox)txtItem);
                            }
                        }
                    }
                }
            }
            //组合对象存入数据库

            if (ctr.Parent.Parent is TabControl)
            {
                WaterTestConfigureSet w = new WaterTestConfigureSet();
                w.WaterTestConfigureSet_frequency = Convert.ToInt32(((TabPage)ctr.Parent).Tag);//第几次检测

                DataTable dt = LinQBaseDao.Query("select TestItems_ID from TestItems where TestItems_NAME = '" + ctr.Text + "'").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    w.WaterTestConfigureSet_TestItems_TestItems_ID = Convert.ToInt32(dt.Rows[0][0]);//检测项目编号
                }
                else
                {
                    return(0);
                }
                w.WaterTestConfigureSet_Project = WaterTestConfigureSet_Project;//方案号


                if (tbxList.Count == 2)
                {
                    w.WaterTestConfigureSet_PackCount   = Convert.ToInt32(tbxList[0].Text == "" ? "0" : tbxList[0].Text);
                    w.WaterTestConfigureSet_NeedleCount = Convert.ToInt32(tbxList[1].Text == "" ? "0" : tbxList[1].Text);
                }
                if (tbxList.Count == 1)
                {
                    w.WaterTestConfigureSet_NeedleCount = Convert.ToInt32(tbxList[0].Text == "" ? "0" : tbxList[0].Text);
                }
                else if (tbxList.Count > 2)
                {
                    return(0);
                }
                Expression <Func <WaterTestConfigureSet, bool> > fn = n => n.WaterTestConfigureSet_frequency == w.WaterTestConfigureSet_frequency && n.WaterTestConfigureSet_TestItems_TestItems_ID == w.WaterTestConfigureSet_TestItems_TestItems_ID;

                if (WaterTestConfigureSetDAL.Single(fn) == null)
                {
                    bool b = WaterTestConfigureSetDAL.InsertOneQCRecord(w);
                }
                else
                {
                    Action <WaterTestConfigureSet> a = n =>
                    {
                        n.WaterTestConfigureSet_frequency = w.WaterTestConfigureSet_frequency;
                        n.WaterTestConfigureSet_TestItems_TestItems_ID = w.WaterTestConfigureSet_TestItems_TestItems_ID;
                        n.WaterTestConfigureSet_Project     = w.WaterTestConfigureSet_Project;
                        n.WaterTestConfigureSet_NeedleCount = w.WaterTestConfigureSet_NeedleCount;
                        n.WaterTestConfigureSet_PackCount   = w.WaterTestConfigureSet_PackCount;
                    };
                    bool b = WaterTestConfigureSetDAL.Update(fn, a);
                    return(1);
                }
            }
            return(0);
        }