def onSave(self):
        # 根据id查找工作面
        work_surf = SQLClientHelper.GetWorkSurfById(self.work_surf_id)
        work_surf_id = work_surf.id
        if work_surf_id <= 0:
            UiHelper.MessageBox(u'sorry,出了点问题,请联系技术人员(错误码:P3)!')
            return

        # 提取钻场参数
        hdsp = SQLClientHelper.GetHighDrillingSiteParamByForeignKey(
            'work_surf_id', work_surf_id)

        if hdsp.id <= 0:
            hdsp = HighDrillingSiteParam()
            hdsp.work_surf_id = work_surf_id

        hdsp.hn, ok = self.ui.hn.text().toDouble()
        hdsp.hs, ok = self.ui.hs.text().toDouble()
        hdsp.theta, ok = self.ui.theta.text().toDouble()
        hdsp.rtn, ok = self.ui.rtn.text().toDouble()
        hdsp.q, ok = self.ui.q.text().toDouble()

        # 保存到数据库
        ret = False
        if work_surf_id <= 0:
            ret = SQLClientHelper.AddHighDrillingSiteParam(hdsp) > 0
        else:
            ret = SQLClientHelper.UpdateHighDrillingSiteParam(hdsp)

        if ret:
            UiHelper.MessageBox(u'更新数据成功!')
        else:
            UiHelper.MessageBox(u'sorry,出了点问题,请联系技术人员(错误码:P4)!')
    def onDrillSite(self):
        # 当前选中的工作面
        index = self.ui.work_surf.currentIndex()
        if index < 0: return

        work_surf_id, ok = self.ui.work_surf.itemData(index).toInt()
        work_surf = SQLClientHelper.GetWorkSurfById(work_surf_id)
        if work_surf.id <= 0:
            UiHelper.MessageBox(u'请选择一个工作面!')
            return

        # 显示钻场设计对话框
        dlg = HighDrillingSiteDlg(work_surf.id)
        dlg.exec_()

        # 计算钻场参数
        hdsp = SQLClientHelper.GetHighDrillingSiteParamByForeignKey(
            'work_surf_id', work_surf.id)
        if hdsp.id <= 0: return
        hn, Rtn, q, hs, theta = hdsp.hn, hdsp.rtn, hdsp.q, hdsp.hs, hdsp.theta
        L1 = hn * sqrt(2.0 * Rtn / q) + 2 * hs / tan(radians(theta))
        L2 = hn * sqrt(2.0 * Rtn / (3 * q))
        Lg = L2

        # 更新到界面
        self.ui.l1.setText(u'%.1f' % L1)
        self.ui.l2.setText(u'%.1f' % L2)
        self.ui.lg.setText(u'%.1f' % Lg)
    def onSave(self):
        # 当前选中的工作面
        index = self.ui.work_surf.currentIndex()
        if index < 0: return

        work_surf_id, ok = self.ui.work_surf.itemData(index).toInt()
        work_surf = SQLClientHelper.GetWorkSurfById(work_surf_id)
        if work_surf.id <= 0:
            UiHelper.MessageBox(u'请选择一个工作面!')
            return

        # 提取钻场参数
        hdsp = SQLClientHelper.GetHighDrillingSiteParamByForeignKey(
            'work_surf_id', work_surf.id)
        if hdsp.id <= 0:
            UiHelper.MessageBox(u'sorry, 出了点问题,请联系技术人员(错误码:U1')
            return

        hdsp.l1, ok = self.ui.l1.text().toDouble()
        hdsp.l2, ok = self.ui.l2.text().toDouble()
        hdsp.lg, ok = self.ui.lg.text().toDouble()

        # 保存钻场数据到数据库
        if not SQLClientHelper.UpdateHighDrillingSiteParam(hdsp):
            UiHelper.MessageBox(u'sorry, 出了点问题,请联系技术人员(错误码:U2')
            return

        # 从数据库中提取钻孔参数数据
        hdpp = SQLClientHelper.GetHighDrillingPoreParamByForeignKey(
            'work_surf_id', work_surf.id)
        if hdpp.id <= 0:
            UiHelper.MessageBox(u'sorry, 出了点问题,请联系技术人员(错误码:U3')
            return

        # 删除与钻孔参数关联的所有高位抽采钻孔
        pore_id_lists = SQLClientHelper.GetHighDrillingPoreIdListByForeignKey(
            'high_drilling_pore_param_id', hdpp.id)
        SQLClientHelper.DeleteMoreHighDrillingPore(pore_id_lists)

        # 保存abc列表中的钻孔
        pores = self.getPores(self.ui.abc, hdpp.id)
        # 集中提交到数据库
        SQLClientHelper.AddMoreHighDrillingPore(pores)

        # bcd
        pores = self.getPores(self.ui.bcd, hdpp.id)
        # 集中提交到数据库
        SQLClientHelper.AddMoreHighDrillingPore(pores)

        UiHelper.MessageBox(u'保存高抽巷钻场和钻孔数据成功!')
        # self.accept()
        pass
    def fillDatas(self):
        # 根据id查找工作面
        work_surf = SQLClientHelper.GetWorkSurfById(self.work_surf_id)
        if work_surf.id <= 0:
            UiHelper.MessageBox(u'sorry,出了点问题,请联系技术人员(错误码:P1)!')
            return

        # 提取钻场参数
        hdsp = SQLClientHelper.GetHighDrillingSiteParamByForeignKey(
            'work_surf_id', work_surf.id)
        if hdsp.id <= 0:
            UiHelper.MessageBox(u'sorry, 出了点问题,请联系技术人员(错误码:P2')
            return

        self.ui.hn.setText(u'%.1f' % hdsp.hn)
        self.ui.hs.setText(u'%.1f' % hdsp.hs)
        self.ui.theta.setText(u'%.1f' % hdsp.theta)
        self.ui.rtn.setText(u'%.1f' % hdsp.rtn)
        self.ui.q.setText(u'%.1f' % hdsp.q)
    def onWorkSurfChanged(self, index):
        work_surf_id, ok = self.ui.work_surf.itemData(index).toInt()
        work_surf = SQLClientHelper.GetWorkSurfById(work_surf_id)
        if work_surf.id <= 0: return
        work_area = SQLClientHelper.GetWorkAreaById(work_surf.work_area_id)
        if work_area.id <= 0: return
        coal = SQLClientHelper.GetCoalById(work_area.coal_id)
        if coal.id <= 0: return

        # 填充高抽巷钻场的数据
        hdsp = SQLClientHelper.GetHighDrillingSiteParamByForeignKey(
            'work_surf_id', work_surf_id)
        if hdsp.id <= 0:
            self.ui.l1.setText(u'0.0')
            self.ui.l2.setText(u'0.0')
            self.ui.lg.setText(u'0.0')
        else:
            self.ui.l1.setText(u'%.1f' % hdsp.l1)
            self.ui.l2.setText(u'%.1f' % hdsp.l2)
            self.ui.lg.setText(u'%.1f' % hdsp.lg)

        # 填充高抽巷钻孔的数据
        hdpp = SQLClientHelper.GetHighDrillingPoreParamByForeignKey(
            'work_surf_id', work_surf_id)
        # 清空abc和bcd表格
        self.ui.abc.clearContents()
        self.ui.bcd.clearContents()
        # 测试代码
        # self.ui.abc.setRowCount(5)
        # self.ui.abc.setItem(0, 0, QtGui.QTableWidgetItem('1'))
        # self.ui.abc.setItem(0, 1, QtGui.QTableWidgetItem('2'))
        # self.ui.abc.setItem(0, 2, QtGui.QTableWidgetItem('3'))
        # self.ui.abc.setItem(0, 3, QtGui.QTableWidgetItem('4'))
        # return
        if hdpp.id > 0:
            # 查找abc范围的钻孔(type=0表示abc区域)
            abc_pore_lists = SQLClientHelper.GetHighDrillingPoreListByField2(
                'high_drilling_pore_param_id', str(hdpp.id), 'pore_type',
                str(0))
            # 设置行数
            self.ui.abc.setRowCount(len(abc_pore_lists))
            for i, pore in enumerate(abc_pore_lists):
                self.ui.abc.setItem(i, 0,
                                    QtGui.QTableWidgetItem(u'%d' % pore.num))
                self.ui.abc.setItem(
                    i, 1, QtGui.QTableWidgetItem(u'%1.f' % pore.length))
                self.ui.abc.setItem(
                    i, 2, QtGui.QTableWidgetItem(u'%.1f' % pore.angle))
                # self.ui.abc.setItem(i, 3, QtGui.QTableWidgetItem(u'%.1f' % pore.azimuth_angle))

            # 查找bcd范围的钻孔(type=1表示bcd区域)
            bcd_pore_lists = SQLClientHelper.GetHighDrillingPoreListByField2(
                'high_drilling_pore_param_id', str(hdpp.id), 'pore_type',
                str(1))
            # 设置行数
            self.ui.abc.setRowCount(len(bcd_pore_lists))
            for i, pore in enumerate(bcd_pore_lists):
                self.ui.abc.setItem(i, 0,
                                    QtGui.QTableWidgetItem(u'%d' % pore.num))
                self.ui.abc.setItem(
                    i, 1, QtGui.QTableWidgetItem(u'%1.f' % pore.length))
                self.ui.abc.setItem(
                    i, 2, QtGui.QTableWidgetItem(u'%.1f' % pore.angle))