Exemplo n.º 1
0
        public static PayslipDocument ExportStaffPayslip(int payslip, string company)
        {
            string path = Properties.Settings.Default.ExportPath;
            string cString = Properties.Settings.Default.DB;
            SqlConnection objCon = new SqlConnection(cString);
            SqlCommand objCmd = null;
            SqlDataAdapter objAdapter = null;
            DataSet ds = null;
            PayslipDocument meta = new PayslipDocument();
            try
            {
                objCon.Open();
                objCmd = new SqlCommand("GetStaffPayslip", objCon);
                objCmd.CommandType = CommandType.StoredProcedure;
                objCmd.Parameters.Add("@PayslipID", SqlDbType.Int).Value = payslip;
                objCmd.Parameters.Add("@Company", SqlDbType.VarChar, 12).Value = company;

                // Create a SqlDataAdapter.
                objAdapter = new SqlDataAdapter();
                objAdapter.SelectCommand = objCmd;
                ds = new DataSet("PaySlip");
                objAdapter.Fill(ds);
                objCon.Close();
                ds.Tables[0].TableName = "FUNC_DP";
                ds.Tables[1].TableName = "FUNC_VENC";
                ds.Tables[2].TableName = "Recibos";
                ds.Tables[3].TableName = "RecibosDetalhes";
                ds.Tables[4].TableName = "Seguros";
                ds.Tables[5].TableName = "SegurancaSocial";
                if (path[path.Length - 1] != '\\')
                    path += "\\GRH\\";
                else
                    path += "GRH\\";
                path += ds.Tables[2].Rows[0].ItemArray[1] + "-" + Convert.ToString(ds.Tables[2].Rows[0].ItemArray[2]).PadLeft(2, '0') + "\\";

                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);

                meta.NIF = ds.Tables["FUNC_DP"].Rows[0].ItemArray[1].ToString();
                meta.RecordID = Convert.ToInt32(ds.Tables["Recibos"].Rows[0].ItemArray[5]);
                meta.Date = new DateTime(Convert.ToInt32(ds.Tables["Recibos"].Rows[0].ItemArray[1]), Convert.ToInt32(ds.Tables["Recibos"].Rows[0].ItemArray[2]), 1);
                meta.Description = ds.Tables["Recibos"].Rows[0].ItemArray[1].ToString() + '/' +
                                            ds.Tables["Recibos"].Rows[0].ItemArray[2].ToString().PadLeft(2, '0') + ' ' +
                                            ds.Tables["Recibos"].Rows[0].ItemArray[3].ToString();
                meta.SystemName = "GRH";
                meta.MetaPath = path + payslip + ".xml";
                meta.DocumentPath = path + payslip + ".pdf";

                if (File.Exists(meta.MetaPath))
                    File.Delete(meta.MetaPath);

                if (File.Exists(meta.DocumentPath))
                    File.Delete(meta.DocumentPath);

                using (ReportDocument cryRpt = new ReportDocument())
                {
                    cryRpt.Load(Properties.Settings.Default.PayslipStaff);
                    // Show corporate image
                    cryRpt.ReportDefinition.ReportObjects["Picture1"].ObjectFormat.EnableSuppress = false;
                    cryRpt.ReportDefinition.ReportObjects["Text1"].ObjectFormat.EnableSuppress = false;
                    cryRpt.ReportDefinition.ReportObjects["Text19"].ObjectFormat.EnableSuppress = false;
                    // set the data source of the report
                    cryRpt.SetDataSource(ds);
                    cryRpt.ExportToDisk(ExportFormatType.PortableDocFormat, meta.DocumentPath);
                }
                meta.SaveMetadata(meta.MetaPath);
                return meta;
            }
            finally
            {
                if (ds != null)
                    ds.Dispose();
                if (objAdapter != null)
                    objAdapter.Dispose();
                if (objCmd != null)
                    objCmd.Dispose();
                if (objCon != null)
                {
                    if(objCon.State != ConnectionState.Closed)
                        objCon.Close();
                    objCon.Dispose();
                }
            }
        }
Exemplo n.º 2
0
 public static void InsertDocument(PayslipDocument meta)
 {
     string path = Properties.Settings.Default.ExportPath;
     string cString = Properties.Settings.Default.DB;
     SqlConnection objCon = new SqlConnection(cString);
     SqlCommand objCmd = null;
     try
     {
         objCon.Open();
         objCmd = new SqlCommand("AddDocument", objCon);
         objCmd.CommandType = CommandType.StoredProcedure;
         objCmd.Parameters.Add("@NIF", SqlDbType.VarChar, 12).Value = meta.NIF;
         objCmd.Parameters.Add("@Path", SqlDbType.VarChar, 200).Value = meta.DocumentPath;
         objCmd.Parameters.Add("@DocType", SqlDbType.VarChar, 20).Value = "Payslip";
         objCmd.Parameters.Add("@Description", SqlDbType.VarChar, 200).Value = meta.Description;
         objCmd.Parameters.Add("@SystemName", SqlDbType.VarChar, 10).Value = meta.SystemName;
         objCmd.Parameters.Add("@RecordType", SqlDbType.VarChar, 10).Value = "Recibo";
         objCmd.Parameters.Add("@RecordID", SqlDbType.Int).Value = meta.RecordID;
         objCmd.ExecuteNonQuery();
     }
     finally
     {
         if (objCmd != null)
             objCmd.Dispose();
         if (objCon != null)
         {
             if (objCon.State != ConnectionState.Closed)
                 objCon.Close();
             objCon.Dispose();
         }
     }
 }