Newer
Older
GHFX_REFACTOR / FrmAPPFORASK.cs
wxn on 2 Nov 2016 12 KB 提交
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Collections;

namespace Cyberpipe
{
    public partial class FrmAPPFORASK : Office2007Form
    {
        static public string refuseReason="";
        static public string auditor = "";

        string strMark = "";
        static public ArrayList auditorlist;

        public FrmAPPFORASK(string str)
        {
            InitializeComponent();
            dataGridViewX1.Columns["申请时间"].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss";//datagridview中时间格式显示控制
            strMark = str;

            string sqlQx = "select * from casic_userinfotest t where t.APPR = 1";
            if (strMark == "专题图审核")
            {
                this.Text = "专题图审核";
                //dataGridViewX1.Columns["申请状态"].DataPropertyName = "mapstatus";
            }
            if (strMark == "打印审核")
            {
                this.Text = "打印审核";
                //dataGridViewX1.Columns["申请状态"].DataPropertyName = "printstatus";
            }
            if (strMark == "拷贝审核")
            {
                this.Text = "拷贝审核";
                //dataGridViewX1.Columns["申请状态"].DataPropertyName = "copystatus";
            }
            //找到有审批权限的人加入到审核人列表中
            DataTable dt = OledbHelper.QueryTable(sqlQx);
            auditorlist = new ArrayList();
            for (int i = 0; i < dt.Rows.Count; i++)
            { 
                if (dt.Rows[i]["USERNAME"].ToString() != Utility.userName)
                {
                    auditorlist.Add(dt.Rows[i]["USERNAME"].ToString()); 
                }
            }  
        }

        private void FrmAPPFORASK_Load(object sender, EventArgs e)
        {
            if (strMark == "专题图审核")
            {
                string sql = "select t1.DBID,t1.APPLICANT,t1.APPLICATIONTIME,t1.CONTENT,t1.NT,t1.STATUS,'批准' as \"批准\",'不批准' as \"不批准\" from CASIC_APP_WORKSHEET t1 join CASIC_APP_WORKSHEET_TYPE t2 on t1.worksheettype_id=t2.dbid where NAME='专题图' and STATUS = '待审核' order by t1.APPLICATIONTIME desc";
                DataTable dt = OledbHelper.QueryTable(sql);
                dataGridViewX1.DataSource = dt;

            }
            if (strMark == "打印审核")
            {
                string sql = "select t1.DBID,t1.APPLICANT,t1.APPLICATIONTIME,t1.CONTENT,t1.NT,t1.STATUS,'批准' as \"批准\",'不批准' as \"不批准\" from CASIC_APP_WORKSHEET t1 join CASIC_APP_WORKSHEET_TYPE t2 on t1.worksheettype_id=t2.dbid where NAME='打印' and STATUS = '待审核' order by t1.APPLICATIONTIME desc";
                DataTable dt = OledbHelper.QueryTable(sql);
                dataGridViewX1.DataSource = dt;

            }
            if (strMark == "拷贝审核")
            {
                string sql = "select t1.DBID,t1.APPLICANT,t1.APPLICATIONTIME,t1.CONTENT,t1.NT,t1.STATUS,'批准' as \"批准\",'不批准' as \"不批准\" from CASIC_APP_WORKSHEET t1 join CASIC_APP_WORKSHEET_TYPE t2 on t1.worksheettype_id=t2.dbid where NAME='拷贝' and STATUS = '待审核' order by t1.APPLICATIONTIME desc";
                DataTable dt = OledbHelper.QueryTable(sql);
                dataGridViewX1.DataSource = dt;

            }

            //if (Utility.userRole.IndexOf("申请审批") == -1)
            //{
            //    dataGridViewX1.Columns[6].Visible = false;
            //    dataGridViewX1.Columns[7].Visible = false;
            //}

        }
        
        private void dataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            System.DateTime current = new System.DateTime();
            current = System.DateTime.Now;
            if (e.RowIndex != -1 && e.ColumnIndex != -1)
            {
                if (strMark == "专题图审核")
                {
                    int dbid = Convert.ToInt32(dataGridViewX1.Rows[e.RowIndex].Cells["编号"].Value.ToString()); 
                    string status = Convert.ToString(dataGridViewX1.Rows[e.RowIndex].Cells["申请状态"].Value);
                    string applicant = Convert.ToString(dataGridViewX1.Rows[e.RowIndex].Cells["申请人"].Value);

                    if (dataGridViewX1.Columns[e.ColumnIndex].HeaderText == "批准")
                    { 
                        if ((status == "待审核")&&(Utility.userName!=applicant))
                        { 
                                if (MessageBox.Show("你确认要批准该申请?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {   
                                    string sql = "update casic_app_worksheet set STATUS = '" + "审核已通过" 
                                        + "',AUDITIONTIME = to_date('" + current.ToString("yyyy-MM-dd HH:mm:ss") 
                                        + "','yyyy-MM-dd hh24:mi:ss'),AUDITOR = '" + Utility.userName + "' where DBID = " + dbid;
                                    OledbHelper.sqlExecuteNonQuery(sql);
                                    dataGridViewX1.Rows[e.RowIndex].Cells["申请状态"].Value = "审核已通过"; 
                                } 
                        }
                        else if(Utility.userName==applicant){
                            MessageBox.Show("本人不能审批自己的申请");
                        } else if(status!="待审核"){
                            MessageBox.Show("该申请已经被审核");
                        }
                    }
                    if (dataGridViewX1.Columns[e.ColumnIndex].HeaderText == "不批准")
                    {
                        if ((status == "待审核")&&(Utility.userName!=applicant)) { 
                                FrmAPPFORASKReason frmreason = new FrmAPPFORASKReason(Utility.userName, dbid);
                                frmreason.ShowDialog();

                                dataGridViewX1.Rows[e.RowIndex].Cells["申请状态"].Value = refuseReason;  
                        }
                        else if (Utility.userName == applicant)
                        {
                            MessageBox.Show("本人不能审批自己的申请");
                        }
                        else if (status != "待审核")
                        {
                            MessageBox.Show("该申请已经被审核");

                        }
                      
                    } 
                }
                if (strMark == "打印审核")
                {
                    int dbid = Convert.ToInt32(dataGridViewX1.Rows[e.RowIndex].Cells["编号"].Value.ToString());
                    string status = Convert.ToString(dataGridViewX1.Rows[e.RowIndex].Cells["申请状态"].Value);
                    string applicant = Convert.ToString(dataGridViewX1.Rows[e.RowIndex].Cells["申请人"].Value);

                    if (dataGridViewX1.Columns[e.ColumnIndex].HeaderText == "批准")
                    {
                        if ((status == "待审核")&&(Utility.userName!=applicant))
                        { 
                                if (MessageBox.Show("你确认要批准该申请?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    string sql = "update casic_app_worksheet set STATUS = '" + "审核已通过" + "',AUDITIONTIME = to_date('" + current.ToString("yyyy-MM-dd HH:mm:ss")
                                        + "','yyyy-MM-dd hh24:mi:ss'),AUDITOR = '" + Utility.userName + "' where DBID = " + dbid;
                                    OledbHelper.sqlExecuteNonQuery(sql);
                                    dataGridViewX1.Rows[e.RowIndex].Cells["申请状态"].Value = "审核已通过"; 
                                } 

                        }
                        else if (Utility.userName == applicant)
                        {
                            MessageBox.Show("本人不能审批自己的申请");
                        }
                        else if (status != "待审核")
                        {
                            MessageBox.Show("该申请已经被审核");

                        }
                    }
                    if (dataGridViewX1.Columns[e.ColumnIndex].HeaderText == "不批准")
                    {
                        if ((status == "待审核")&&(Utility.userName!=applicant))
                        {
                            FrmAPPFORASKReason frmreason = new FrmAPPFORASKReason(Utility.userName, dbid);
                                frmreason.ShowDialog();

                                dataGridViewX1.Rows[e.RowIndex].Cells["申请状态"].Value = refuseReason; 
                            
                        }
                        else if (Utility.userName == applicant)
                        {
                            MessageBox.Show("本人不能审批自己的申请");
                        }
                        else if (status != "待审核")
                        {
                            MessageBox.Show("该申请已经被审核");

                        }
                    } 
                }
                if (strMark == "拷贝审核")
                {
                    int dbid = Convert.ToInt32(dataGridViewX1.Rows[e.RowIndex].Cells["编号"].Value.ToString());
                    string status = Convert.ToString(dataGridViewX1.Rows[e.RowIndex].Cells["申请状态"].Value);
                    string applicant = Convert.ToString(dataGridViewX1.Rows[e.RowIndex].Cells["申请人"].Value);

                    if (dataGridViewX1.Columns[e.ColumnIndex].HeaderText == "批准")
                    {
                        if ((status == "待审核") && (Utility.userName != applicant))
                        { 
                                if (MessageBox.Show("你确认要批准该申请?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                {
                                    string sql = "update casic_app_worksheet set STATUS = '" + "审核已通过" 
                                        + "',AUDITIONTIME = to_date('" + current.ToString("yyyy-MM-dd HH:mm:ss")
                                        + "','yyyy-MM-dd hh24:mi:ss'),AUDITOR = '" + Utility.userName + "' where DBID = " + dbid;
                                    OledbHelper.sqlExecuteNonQuery(sql);
                                    dataGridViewX1.Rows[e.RowIndex].Cells["申请状态"].Value = "审核已通过";
                                } 
                        }
                        else if (Utility.userName == applicant)
                        {
                            MessageBox.Show("本人不能审批自己的申请");
                        }
                        else if (status != "待审核")
                        {
                            MessageBox.Show("该申请已经被审核");

                        }
                    }
                    if (dataGridViewX1.Columns[e.ColumnIndex].HeaderText == "不批准") {
                        if ((status == "待审核")&&(Utility.userName!=applicant))
                        {

                            FrmAPPFORASKReason frmreason = new FrmAPPFORASKReason(Utility.userName, dbid);
                                frmreason.ShowDialog();

                                dataGridViewX1.Rows[e.RowIndex].Cells["申请状态"].Value = refuseReason;  
                        }
                        else if (Utility.userName == applicant)
                        {
                            MessageBox.Show("本人不能审批自己的申请");
                        }
                        else if (status != "待审核")
                        {
                            MessageBox.Show("该申请已经被审核");

                        }
                    } 
                } 
            }
        } 
    }
}