Example #1
0
        void btViewContract_Click(object sender, EventArgs e)
        {
            try
            {
                string HDLD    = Parameters.GetParaValue("HDLD").ToString();    // "HDLD20180824";
                string HDLD2   = Parameters.GetParaValue("HDLD2").ToString();   // "HDLD20180824";-- Hợp đồng không thời hạn
                string HDLD_PL = Parameters.GetParaValue("HDLDPL").ToString();  //"HDLD20180824_PL";
                string HDLD_HL = Parameters.GetParaValue("HDLDHL").ToString();  //"HDLD20180824_PL";--  -- Hợp đồng huấn luyện

                if (tabDetail.SelectedTab == pageHopDong || dgvHopDong.Focused) // View hop dong
                {
                    if (bdsHopDong.Position < 0)
                    {
                        return;
                    }

                    DataRow drCurrentHD = ((DataRowView)bdsHopDong.Current).Row;

                    string    strSQLProc  = "sp_GetHDLDInfo";
                    Hashtable htParameter = new Hashtable();
                    htParameter.Add("MA_CBNV", drCurrentHD["Ma_Cbnv"].ToString());
                    htParameter.Add("SO_HD", drCurrentHD["So_Hd"].ToString());
                    htParameter.Add("SO_PL", string.Empty);
                    DataTable dtResult = SQLExec.ExecuteReturnDt(strSQLProc, htParameter, CommandType.StoredProcedure);



                    string fileName       = DataTool.SQLGetNameByCode("SYSRESOURCES", "FILE_ID", "FILE_ID", HDLD);
                    object objFileContent = Resource.LoadResource(HDLD);
                    if (drCurrentHD["Loai_Hd"].ToString() == "5")
                    {
                        fileName       = DataTool.SQLGetNameByCode("SYSRESOURCES", "FILE_ID", "FILE_ID", HDLD_HL);
                        objFileContent = Resource.LoadResource(HDLD_HL);
                    }
                    if (drCurrentHD["Loai_Hd"].ToString() == "2")
                    {
                        fileName       = DataTool.SQLGetNameByCode("SYSRESOURCES", "FILE_ID", "FILE_ID", HDLD2);
                        objFileContent = Resource.LoadResource(HDLD2);
                    }

                    string strFileTemplate = Application.StartupPath + @"\Template\" + fileName;


                    if (objFileContent != null)
                    {
                        FileStream stream = new FileStream(strFileTemplate, FileMode.Create, FileAccess.ReadWrite);
                        stream.Write((byte[])objFileContent, 0, ((byte[])objFileContent).Length);
                        stream.Close();
                    }
                    else
                    {
                        EpointMessage.MsgOk("Tập tin rỗng");
                    }



                    HRMCommon.WriteToWordQTTC04(dtResult, strFileTemplate, fileName);
                }
                else if (tabDetail.SelectedTab == pageHopDongPL || dgvHopDongPL.Focused)//View phụ lục hợp đồng
                {
                    if (bdsHopDongPL.Position < 0)
                    {
                        return;
                    }

                    DataRow drCurrentPL = ((DataRowView)bdsHopDongPL.Current).Row;
                    if (drCurrentPL["File_Id"].ToString() != string.Empty)
                    {
                        HDLD_PL = drCurrentPL["File_Id"].ToString();
                    }

                    string fileName        = DataTool.SQLGetNameByCode("SYSRESOURCES", "FILE_ID", "FILE_ID", HDLD_PL);
                    string strFileTemplate = Application.StartupPath + @"\Template\" + fileName;

                    object objFileContent = Resource.LoadResource(HDLD_PL);
                    if (objFileContent != null)
                    {
                        FileStream stream = new FileStream(strFileTemplate, FileMode.Create, FileAccess.ReadWrite);
                        stream.Write((byte[])objFileContent, 0, ((byte[])objFileContent).Length);
                        stream.Close();
                    }
                    else
                    {
                        EpointMessage.MsgOk("Tập tin rỗng");
                    }


                    string    strSQLProc  = "sp_GetHDLDInfo";
                    Hashtable htParameter = new Hashtable();
                    htParameter.Add("MA_CBNV", drCurrentPL["Ma_Cbnv"].ToString());
                    htParameter.Add("SO_HD", string.Empty);
                    htParameter.Add("SO_PL", drCurrentPL["So_Pl"].ToString());
                    DataTable dtResult = SQLExec.ExecuteReturnDt(strSQLProc, htParameter, CommandType.StoredProcedure);
                    if (dtResult != null && dtResult.Rows.Count > 0)
                    {
                        HRMCommon.WriteToWordQTTC04(dtResult, strFileTemplate, fileName);
                    }
                    else
                    {
                        EpointMessage.MsgOk("Không xuất được báo cáo!");
                    }
                }
            }
            catch (Exception ex)
            {
                EpointMessage.MsgOk(ex.Message);
            }
        }