示例#1
0
        /// <summary>
        /// Chung cho thực hiện các thông tin, báo cáo in ngay
        /// </summary>
        /// <param name="maBaoCao"></param>
        /// <param name="listThamSoBaoCao"></param>
        public void LayDuLieu(string maBaoCao, List <ThamSoBaoCao> listThamSoBaoCao)
        {
            try
            {
                DatabaseConstant.Action action = DatabaseConstant.Action.IN;

                // Lấy thông tin báo cáo và tham số
                BaoCaoProcess        process        = new BaoCaoProcess();
                int                  idBaoCao       = 0;
                HT_BAOCAO            htBaoCao       = null;
                List <HT_BAOCAO_TSO> lstHtBaoCaoTso = null;
                process.LayThongTinBaoCao(idBaoCao, maBaoCao, ref htBaoCao, ref lstHtBaoCaoTso);

                List <HT_BAOCAO_TSO> listHtBaoCaoTso = lstHtBaoCaoTso;
                DataSet ds = new DataSet();

                // Chuẩn bị điều kiện cho báo cáo
                if (listThamSoBaoCao != null && listThamSoBaoCao.Count > 0)
                {
                    if (listHtBaoCaoTso.Where(t => t.LOAI_TSO == ApplicationConstant.LoaiThamSoBaoCao.SQL.layGiaTri() && t.MA_TSO.Equals("@DT_THAMSO")).Count() > 0)
                    {
                        listHtBaoCaoTso = new List <HT_BAOCAO_TSO>();
                        foreach (ThamSoBaoCao thamSoBaoCao in listThamSoBaoCao)
                        {
                            HT_BAOCAO_TSO tso = new HT_BAOCAO_TSO();
                            tso.MA_TSO   = thamSoBaoCao.MaThamSo;
                            tso.LOAI_TSO = thamSoBaoCao.LoaiThamSo;
                            tso.GTRI_TSO = thamSoBaoCao.GiaTriThamSo;
                            listHtBaoCaoTso.Add(tso);
                        }
                    }
                    else
                    {
                        foreach (HT_BAOCAO_TSO htBaoCaoTso in listHtBaoCaoTso)
                        {
                            foreach (ThamSoBaoCao thamSoBaoCao in listThamSoBaoCao)
                            {
                                if (htBaoCaoTso.MA_TSO.Equals(thamSoBaoCao.MaThamSo) &&
                                    htBaoCaoTso.LOAI_TSO.Equals(thamSoBaoCao.LoaiThamSo))
                                {
                                    htBaoCaoTso.GTRI_TSO = thamSoBaoCao.GiaTriThamSo;
                                    break;
                                }
                                if (!LObject.IsNullOrEmpty(thamSoBaoCao.DsThamSo))
                                {
                                    ds = thamSoBaoCao.DsThamSo;
                                }
                            }
                        }
                    }
                }
                else
                {
                    return;
                }

                ApplicationConstant.ResponseStatus retStatus = ApplicationConstant.ResponseStatus.KHONG_THANH_CONG;
                FileBase        fileResponse    = new FileBase();
                List <FileBase> lstFileResponse = new List <FileBase>();
                string          responseMessage = null;

                retStatus = process.LayDuLieu(htBaoCao, listHtBaoCaoTso, ref fileResponse, ref responseMessage, ds, action);

                if (retStatus == ApplicationConstant.ResponseStatus.THANH_CONG)
                {
                    string fileReport = ClientInformation.TempDir + "\\" + fileResponse.FileName + "." + fileResponse.FileFormat;;
                    LFile.WriteFileFromByteArray(fileResponse.FileData, fileReport);

                    // show file
                    Stream stream = LFile.ConvertByteArrayToStream(fileResponse.FileData);
                    System.Diagnostics.Process.Start(fileReport);
                }
                else
                {
                    LMessage.ShowMessage(responseMessage, LMessage.MessageBoxType.Error);
                    return;
                }
            }
            catch (System.Exception ex)
            {
                LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex);
                GC.Collect();
                CommonFunction.ThongBaoLoi(ex);
            }
        }
示例#2
0
        public ApplicationConstant.ResponseStatus DuLieuChiTieu(DatabaseConstant.Action action, int idBaoCao, ref HT_BAOCAO htBaoCao, ref List <HT_BAOCAO_TSO> lstBaoCaoTso, ref DataSet ds, ref string responseMessage)
        {
            KhaiThacDuLieuServiceClient client   = null;
            KhaiThacDuLieuRequest       request  = null;
            KhaiThacDuLieuResponse      response = null;

            try
            {
                // Kiểm tra kết nối, server, service trước khi request
                Common.Utilities.IsRequestAllow(ApplicationConstant.SystemService.KhaiThacDuLieuService.layGiaTri());

                client   = KhaiThacDuLieuServiceClient(ApplicationConstant.SystemService.KhaiThacDuLieuService);
                request  = Common.Utilities.PrepareRequest(new KhaiThacDuLieuServiceRef.KhaiThacDuLieuRequest());
                response = new KhaiThacDuLieuServiceRef.KhaiThacDuLieuResponse();

                // Khởi tạo request
                request.Function       = DatabaseConstant.Function.KTDL_DM_DL_CT;
                request.Action         = action;
                request.idBaoCao       = idBaoCao;
                request.htBaoCao       = htBaoCao;
                request.lstHtBaoCaoTso = lstBaoCaoTso.ToArray();
                // Gửi yêu cầu tới Server
                response = client.KhaiThacDuLieu(request);

                // Kiểm tra kết quả trả về
                Common.Utilities.ValidResponse(request, response);

                htBaoCao     = response.htBaoCao;
                lstBaoCaoTso = response.lstHtBaoCaoTso != null?response.lstHtBaoCaoTso.ToList() : null;

                ds = response.dsDuLieuBaoCao;
                responseMessage = response.ResponseMessage;
                return(response.ResponseStatus);
            }
            catch (Exception ex)
            {
                LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex);
                throw ex;
            }
            finally
            {
                if (client.State == CommunicationState.Faulted)
                {
                    client.Abort();
                }
                else
                {
                    client.Close();
                }

                client   = null;
                request  = null;
                response = null;
            }
        }