public async static Task<SYS_tblReportCaptionDRO> GetComboDynamicList(string url)
        {
            SYS_tblReportCaptionDRO result = new SYS_tblReportCaptionDRO();
            try
            {
                var response_data = await HttpGet(url);
                if (response_data.ToLower().StartsWith("error"))
                {
                    result.ResponseItem.IsError = true;
                    string[] tmp = response_data.Split('|');
                    result.ResponseItem.ErrorCode = tmp[1];
                    result.ResponseItem.ErrorMessage = tmp[2];
                }
                else
                {
                    var response_collection = JsonConvert.DeserializeObject<SYS_tblReportCaptionDRO>(response_data + "");

                    if (response_collection != null)
                    {
                        result.ComboDynamicList = response_collection.ComboDynamicList;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                result.ResponseItem.Message = ex.Message;
            }

            return result;
        }
        public async static Task<SYS_tblReportCaptionDRO> GetComboDynamicList(string username, string language_id, string code, string table_name, string get_by)
        {
            SYS_tblReportCaptionDRO result = new SYS_tblReportCaptionDRO();
            try
            {
                string url = string.Format(@"{0}/GetComboDynamicList?Username={1}&LanguageID={2}&Code={3}&TableName={4}&GetBy={5}", GetBaseUrl(), username, language_id, code, table_name, get_by);

                result = await SYS_tblReportCaptionDAO.GetComboDynamicList(url);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                result.ResponseItem.Message = ex.Message;
            }

            return result;
        }
        public async static Task<SYS_tblReportCaptionDRO> GetReportCaption(string username, string language_id, string function_id, bool is_import)
        {
            SYS_tblReportCaptionDRO result = new SYS_tblReportCaptionDRO();
            try
            {
                string url = string.Format(@"{0}/GetReportCaption?Username={1}&LanguageID={2}&FunctionID={3}&IsImport={4}", GetBaseUrl(), username, language_id, function_id, is_import);

                result = await SYS_tblReportCaptionDAO.GetReportCaption(url);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                result.ResponseItem.Message = ex.Message;
            }

            return result;
        }
Esempio n. 4
0
        public async static void GetFileWithReportCaption(string username, string language_id, string template, string function_id, string module_id)
        {
            Excel.Application App = null;
            Excel.Workbook Book = null;
            Excel.Worksheet Sheet = null;
            Excel.Range Range = null;
            object Missing = System.Reflection.Missing.Value;
            string strFilePath = "";

            try
            {
                App = new Excel.Application();
                Book = App.Workbooks.Open(string.Format(@"{0}\{1}\{2}", Temp, module_id, template));
                Sheet = (Excel.Worksheet)Book.Worksheets[1];
                Range = Sheet.UsedRange;
                int rowCount = Range.Rows.Count;
                int colCount = Range.Columns.Count;

                SYS_tblReportCaptionDRO captionList = new SYS_tblReportCaptionDRO();
                captionList = await iPOS.BUS.Systems.SYS_tblReportCaptionBUS.GetReportCaption(username, language_id, function_id, true);
                if (!CommonEngine.CheckValidResponseItem(captionList.ResponseItem)) return;

                int index = 1;
                if (captionList != null && captionList.ReportCaptionList.Count > 0)
                {
                    Excel.Range cellRange;
                    SYS_tblReportCaptionDRO comboItems;

                    for (int i = 0; i < captionList.ReportCaptionList.Count; i++)
                    {
                        cellRange = Sheet.Cells.Find("$" + captionList.ReportCaptionList[i].ControlID + "$", Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, Missing, false);
                        if (cellRange != null && cellRange.Cells.Count > 0)
                        {
                            cellRange.Replace("$" + captionList.ReportCaptionList[i].ControlID + "$", captionList.ReportCaptionList[i].Caption, Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns, true, Missing, Missing, Missing);
                            int colIndex = cellRange.Cells.Column;
                            int rowIndex = cellRange.Cells.Row;

                            if (captionList.ReportCaptionList[i].IsComment)
                            {
                                cellRange.AddComment(captionList.ReportCaptionList[i].Comment);
                            }

                            if (captionList.ReportCaptionList[i].IsRequire)
                            {
                                cellRange.Font.Bold = true;
                                cellRange.Font.Color = Color.Red;
                            }

                            if (captionList.ReportCaptionList[i].IsList)
                            {
                                comboItems = new SYS_tblReportCaptionDRO();
                                comboItems = await iPOS.BUS.Systems.SYS_tblReportCaptionBUS.GetComboDynamicList(username, language_id, "", captionList.ReportCaptionList[i].TableName, "Code");
                                index++;
                                if (comboItems != null && comboItems.ComboDynamicList.Count > 0)
                                {
                                    Excel.Worksheet SheetData = null;
                                    if (index > Book.Worksheets.Count)
                                        SheetData = (Excel.Worksheet)Book.Worksheets.Add(Missing, index, Missing, Missing);
                                    else SheetData = (Excel.Worksheet)Book.Worksheets[index];
                                    SheetData.Name = captionList.ReportCaptionList[i].TableName;
                                    Excel.Range RangeData = SheetData.Range[SheetData.Cells[1, 1], SheetData.Cells[1, 2]];
                                    RangeData.Interior.Color = System.Drawing.Color.Yellow;
                                    RangeData.Font.Bold = true;
                                    RangeData.Font.Color = System.Drawing.Color.Red;
                                    SheetData.Cells[1, 1] = "Code";
                                    SheetData.Cells[1, 2] = "Name";

                                    for (int k = 0; k < comboItems.ComboDynamicList.Count; k++)
                                    {
                                        SheetData.Cells[k + 2, 1] = comboItems.ComboDynamicList[k].Code;
                                        SheetData.Cells[k + 2, 2] = comboItems.ComboDynamicList[k].Name;
                                    }

                                    RangeData = SheetData.Range[SheetData.Cells[1, 1], SheetData.Cells[comboItems.ComboDynamicList.Count + 1, 2]];
                                    RangeData.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                                    Excel.Borders BorderData = RangeData.Borders;
                                    BorderData.LineStyle = Excel.XlLineStyle.xlContinuous;
                                    BorderData.Weight = 2d;
                                    RangeData.Columns.AutoFit();
                                    RangeData = Sheet.Range[Sheet.Cells[3, colIndex], Sheet.Cells[rowCount, colIndex]];
                                    RangeData.Validation.Add(Excel.XlDVType.xlValidateList, Excel.XlDVAlertStyle.xlValidAlertStop, Excel.XlFormatConditionOperator.xlBetween, string.Format("={0}!$A$2:$A${1}", captionList.ReportCaptionList[i].TableName, comboItems.ComboDynamicList.Count + 1), Missing);
                                    Range.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                                    RangeData.Validation.InCellDropdown = true;
                                }
                            }
                        }
                    }
                }
                Range.Columns.AutoFit();

                strFilePath = SaveExportCustom(Book, template, false);
                Book.Close(false, Missing, Missing);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return;
            }
            finally
            {
                App.Quit();
                Marshal.FinalReleaseComObject(Range);
                Marshal.FinalReleaseComObject(Sheet);
                Marshal.FinalReleaseComObject(Book);
                Marshal.FinalReleaseComObject(App);
                App = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();

                System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("excel");
                foreach (System.Diagnostics.Process process in processes)
                {
                    if (process.MainWindowTitle.Length == 0)
                        process.Kill();
                }
            }

            System.Diagnostics.Process.Start(strFilePath);
        }