Exemple #1
0
        void btnNonApprove_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("คุณไม่ต้องการอนุมัติเอกสาร : " + txtDocId.Text + " ใช่หรือไม่", "HRDOCS", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            using (ConfirmReject frm = new ConfirmReject())
            {
                frm.Text = "อนุมัติ";

                if (ClassForm.ShowDialog(frm) == DialogResult.Yes)
                {
                    if (con.State == ConnectionState.Open) con.Close();
                    con.Open();

                    SqlCommand sqlCommand = new SqlCommand();
                    sqlCommand.Connection = con;
                    DataTable dt = new DataTable();
                    SqlDataAdapter da = new SqlDataAdapter(sqlCommand);

                    SqlTransaction tr = con.BeginTransaction();
                    sqlCommand.Transaction = tr;
                    if (txtDocId.Text != "")
                    {
                        try
                        {
                            sqlCommand.CommandText = string.Format(
                                @" UPDATE SPC_JN_CHANGHOLIDAYHD SET HEADAPPROVED  = 2
                                 ,HEADAPPROVEDBY = '{0}' 
                                 ,HEADAPPROVEDBYNAME = '{1}'
								 ,HEADAPPROVEDDATE = convert(varchar, getdate(), 23)
                                 ,HEADAPPORVEREMARK = '{2}'
                            WHERE SPC_JN_CHANGHOLIDAYHD.DOCID = @DOCID
                            AND DOCSTAT = 1 "
                                , ClassCurUser.LogInEmplId
                                , ClassCurUser.LogInEmplName
                                , frm.Remark);

                            sqlCommand.Parameters.AddWithValue("@DOCID", txtDocId.Text);
                            sqlCommand.ExecuteNonQuery();

                            tr.Commit();
                            this.IsSaveOnce = true;
                            // MessageBox.Show("เอกสารเลขที่เอกสาร : " + txtDocId.Text + " ทำรายการเรียบร้อยแล้ว");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            if (con.State == ConnectionState.Open) con.Close();
                            this.Close();

                            this.DialogResult = DialogResult.Yes;
                        }
                    }
                }
            }
        }
        void Btn_Reject_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("ต้องการไม่อนุมัติเอกสารนี้ ?", "HRDOCS", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            using (ConfirmReject frm = new ConfirmReject())
            {
                frm.Text = "ไม่อนุมัติ";

                if (ClassForm.ShowDialog(frm) == DialogResult.Yes)
                {

                    DataTable dataTable = new DataTable();
                    SqlTransaction INSTrans = null;
                    SqlConnection sqlConnectionINS = new SqlConnection(DatabaseConfig.ServerConStr);

                    INSTrans = null;
                    sqlConnectionINS.Open();
                    INSTrans = sqlConnectionINS.BeginTransaction();

                    #region UpdateModified

                    using (SqlCommand sqlCommand = new SqlCommand())
                    {
                        sqlCommand.Connection = sqlConnectionINS;
                        sqlCommand.CommandText = @"update SPC_CM_SHIFTHD set HRAPPROVED = 2 ,HRAPPORVEREMARK = @HRAPPORVEREMARK ,
                                                    HRAPPROVEDBY = @HRAPPROVEDBY ,HRAPPROVEDDATE = @HRAPPROVEDDATE 
                                                    ,HRAPPROVEDBYNAME = @HRAPPROVEDBYNAME
                                                    where SPC_CM_SHIFTHD.DSDOCNO = @DSDOCNO ";
                        sqlCommand.Transaction = INSTrans;

                        sqlCommand.Parameters.AddWithValue("@DSDOCNO", DSDOCNO);
                        sqlCommand.Parameters.AddWithValue("@HRAPPORVEREMARK", frm.Remark);
                        sqlCommand.Parameters.AddWithValue("@HRAPPROVEDBY", ClassCurUser.LogInEmplId);
                        sqlCommand.Parameters.AddWithValue("@HRAPPROVEDBYNAME", ClassCurUser.LogInEmplName);
                        sqlCommand.Parameters.AddWithValue("@HRAPPROVEDDATE", MyTime.GetDateTime());
                        sqlCommand.ExecuteNonQuery();

                    }

                    #endregion

                    #region Submit

                    INSTrans.Commit();
                    sqlConnectionINS.Close();

                    #endregion

                    this.DialogResult = DialogResult.Yes;

                }
            }


        }
        void ApproveDL()
        {
            if (MessageBox.Show("คุณต้องการบันทึกเอกสาร ?", "Confirm ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }

            using (ConfirmReject frm = new ConfirmReject())
            {
                frm.Text = "อนุมัติ";

                if (ClassForm.ShowDialog(frm) == DialogResult.Yes)
                {
                    if (con.State == ConnectionState.Open) con.Close();
                    con.Open();

                    SqlCommand sqlCommand = new SqlCommand();
                    sqlCommand.Connection = con;
                    DataTable dt = new DataTable();
                    SqlDataAdapter da = new SqlDataAdapter(sqlCommand);

                    SqlTransaction tr = con.BeginTransaction();
                    sqlCommand.Transaction = tr;
                    if (lbl_DocId.Text != "")
                    {
                        try
                        {
                            sqlCommand.CommandText = string.Format(
                            @"UPDATE SPC_JN_CANCLEDOCHD SET HEADAPPROVED = '1'
								,HEADAPPROVEDBY = @HEADAPPROVEDBY
								,HEADAPPROVEDBYNAME = @HEADAPPROVEDBYNAME
								,HEADAPPROVEDDATE = convert(varchar, getdate(), 23)
                                ,HEADAPPORVEREMARK = '{0}'
                              WHERE DOCID = @DOCID
                              AND DOCSTAT = 1 ", frm.Remark);

                            sqlCommand.Parameters.AddWithValue("@DOCID", _docid);
                            sqlCommand.Parameters.AddWithValue("@HEADAPPROVEDBY", ClassCurUser.LogInEmplId);
                            sqlCommand.Parameters.AddWithValue("@HEADAPPROVEDBYNAME", ClassCurUser.LogInEmplName);
                            sqlCommand.ExecuteNonQuery();

                            tr.Commit();
                            this.IsSaveOnce = true;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                        finally
                        {
                            if (con.State == ConnectionState.Open) con.Close();
                            this.Close();

                            this.DialogResult = DialogResult.Yes;
                        }
                    }
                }
            }
        }