protected void btnAddTeam_Click(object sender, EventArgs e)
        {
            int index = KPI_TeamDal.TeamIDCounts();

            string sID = PageControl.GetGuid();

            KPI_TeamEntity ote = new KPI_TeamEntity();
            ote.TeamID = sID;
            ote.ShiftID = "";
            ote.PersonID = "";
            ote.PositionID = "";
            ote.TeamPersonID = "";
            ote.TeamNote = "";

            ote.TeamCreateTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
            ote.TeamModifyTime = ote.TeamCreateTime;

            if (KPI_TeamDal.Insert(ote))
            {
                //MessageBox.popupClientMessage(this.Page, "添加成功!", "call();");

                gvTeam.EditIndex = index;

                BindTeamByTime();
            }
            else
            {
                MessageBox.popupClientMessage(this.Page, "添加错误!", "call();");

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string selectedPlant = hidSelectedPlant.Value;
            string selectedShift = hidSelectedShift.Value;
            string selectedShiftName = hidSelectedShiftName.Value;
            string selectedPerson = hidSelectPerson.Value;
            string selectedPosition = hidPosition.Value;
            string selectedTeamPerson = hidSelectedTeamPerson.Value;
            string teamNote = txtTeamNote.Text;

            KPI_TeamEntity teamEntity = new KPI_TeamEntity
            {
                PlantID = selectedPlant,
                ShiftID = selectedShift,
                ShiftName=selectedShiftName,
                PersonID = selectedPerson,
                PositionID = selectedPosition,
                TeamPersonID = selectedTeamPerson,
                TeamNote = teamNote
            };

            if (hidFlag.Value == "INSERT")
            {
                if (teamSettingDal.Insert(teamEntity))
                {
                    this.Pager.CurrentPageIndex = 1;
                    BindingData(this.Pager.CurrentPageIndex, this.Pager.PageSize);
                }
            }
            else
            {
                teamEntity.TeamID = hidCode.Value;
                if (teamSettingDal.Update(teamEntity))
                {
                    hidCode.Value = string.Empty;
                    this.Pager.CurrentPageIndex = 1;
                    BindingData(this.Pager.CurrentPageIndex, this.Pager.PageSize);
                }
            }
        }
        protected void gvTeam_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            HtmlInputHidden key = (HtmlInputHidden)gvTeam.Rows[e.RowIndex].Cells[0].FindControl("teamid");

            string sID = key.Value;
            string sShift = ((DropDownList)(gvTeam.Rows[e.RowIndex].Cells[1].FindControl("ddlShift"))).SelectedValue;
            string sPerson = ((DropDownList)(gvTeam.Rows[e.RowIndex].Cells[2].FindControl("ddlPerson"))).SelectedValue;
            //string sPosition = ((DropDownList)(gvTeam.Rows[e.RowIndex].Cells[3].FindControl("ddlPosition"))).SelectedValue;
            string sTeamPerson = ((DropDownList)(gvTeam.Rows[e.RowIndex].Cells[4].FindControl("ddlTeamPerson"))).SelectedValue;
            string sNote = ((TextBox)(gvTeam.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();

            //更新
            KPI_TeamEntity ote = new KPI_TeamEntity();
            ote.TeamID = sID;
            ote.ShiftID = sShift;
            ote.PersonID = sPerson;
            ote.PositionID = KPI_PersonDal.GetPositionID(sPerson); //防止乱选sPosition;
            ote.TeamPersonID = sTeamPerson;
            ote.TeamNote = sNote;
            ote.TeamModifyTime = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");

            if (KPI_TeamDal.Update(ote))
            {
                MessageBox.popupClientMessage(this.Page, "编辑成功!", "call();");

            }
            else
            {
                MessageBox.popupClientMessage(this.Page, "编辑错误!", "call();");

            }

            gvTeam.EditIndex = -1;

            BindTeam();
        }
        protected bool ImportFromExcelToCreate(DataSet ds)
        {
            try
            {
                System.Data.DataTable dt = ds.Tables[0];

                int nAll = dt.Rows.Count;
                int nCreate = 0;
                int nExist = 0;

                foreach(System.Data.DataRow dr in dt.Rows)
                {
                    if (dr["SelectX"].ToString().ToLower() == "x")
                    {
                        //string PersonCode = dr["PersonCode"].ToString().Trim();

                        ////判断是否存在
                        //if (KPI_PersonDal.PersonCodeExists(PersonCode, ""))
                        //{
                        //    //MessageBox.popupClientMessage(this.Page, " 该机组的输出标签已存在!", "call();");
                        //    nExist += 1;
                        //    continue;
                        //}

                        //main tag
                        string keyid = PageControl.GetGuid();
                        KPI_TeamEntity mEntity = new KPI_TeamEntity();
                        mEntity.TeamID = keyid;
                        mEntity.PlantID = KPI_PlantDal.GetPlantID(dr["PlantName"].ToString().Trim());
                        mEntity.ShiftID = KPI_ShiftDal.GetShiftID(dr["ShiftName"].ToString().Trim());
                        mEntity.PersonID = KPI_PersonDal.GetPersonID(dr["PersonCode"].ToString().Trim());
                        mEntity.PositionID = KPI_PersonDal.GetPositionID(mEntity.PersonID);
                        //PersonName,无多大意义
                        mEntity.PositionID = KPI_PositionDal.GetPositionID(dr["PositionName"].ToString().Trim());
                        mEntity.TeamNote = dr["TeamNote"].ToString().Trim();

                        KPI_TeamDal.Insert(mEntity);

                        nCreate += 1;

                    }


                }    
                
                string strInfor = "标签点总数为:{0}个, 创建成功:{1}个,已存在标签点: {2}个。";
                strInfor = string.Format(strInfor, nAll, nCreate, nExist);

                MessageBox.popupClientMessage(this.Page, strInfor, "call();");

                return true;
                                
            }
            catch(Exception ee)
            {
                //
                MessageBox.popupClientMessage(this.Page, ee.Message, "call();");

                return false;
            }              
        }