예제 #1
0
        public async static Task <SYS_tblImportFileConfigDRO> ImportDataRow(string username, string language_id, string store_procedure, System.Data.DataRow dr, string column_array)
        {
            SYS_tblImportFileConfigDRO result = new SYS_tblImportFileConfigDRO();

            try
            {
                Dictionary <string, string> dictionary = new Dictionary <string, string>();
                string[] arrColumn = { };
                arrColumn = column_array.Trim().Split('|');
                if (dr != null && arrColumn.Length > 0)
                {
                    dictionary.Add("Username", username);
                    dictionary.Add("LanguageID", language_id);
                    for (int i = 0; i < arrColumn.Length; i++)
                    {
                        dictionary.Add(arrColumn[i], dr[i] + "");
                    }
                }

                var    json = JsonConvert.SerializeObject(dictionary);
                string url  = string.Format(@"{0}/ImportDataRow?Username={1}&InputData={2}&StoreProcedure={3}", GetBaseUrl(), username, json + "", store_procedure);

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

            return(result);
        }
        public async static Task<SYS_tblImportFileConfigDRO> ImportDataRow(string url)
        {
            SYS_tblImportFileConfigDRO result = new SYS_tblImportFileConfigDRO();
            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_tblImportFileConfigDRO>(response_data + "");

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

            return result;
        }
예제 #3
0
        public async static Task <SYS_tblImportFileConfigDRO> CheckValidImportTemplate(string username, string language_id, string store_procedure, string file_name, string module_id, string function_id)
        {
            SYS_tblImportFileConfigDRO result = new SYS_tblImportFileConfigDRO();

            try
            {
                string url = string.Format(@"{0}/CheckValidImportTemplate?Username={1}&LanguageID={2}&StoreProcedure={3}&FileName={4}&ModuleID={5}&FunctionID={6}", GetBaseUrl(), username, language_id, store_procedure, file_name, module_id, function_id);

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

            return(result);
        }
예제 #4
0
        public async static Task <bool> CheckValidImportTemplate(string username, string language_id, string store_procedure, string file_name, string module_id, string function_id, string file_path)
        {
            bool result = false;

            Excel.Application App   = null;
            Excel.Workbook    Book  = null;
            Excel.Worksheet   Sheet = null;
            Excel.Range       Range = null;

            object Missing = System.Reflection.Missing.Value;

            try
            {
                SYS_tblImportFileConfigDRO tmpItem = await iPOS.BUS.Systems.SYS_tblImportFileConfigBUS.CheckValidImportTemplate(username, language_id, store_procedure, file_name, module_id, function_id);

                if (tmpItem != null && (tmpItem.ImportFileConfigItem != null && tmpItem.ImportFileConfigItem.ImportFileConfigID.ToString() != "0"))
                {
                    result = true;
                }
                else
                {
                    App   = new Excel.Application();
                    Book  = App.Workbooks.Open(file_path);
                    Sheet = (Excel.Worksheet)Book.Worksheets[1];
                    Range = Sheet.UsedRange;
                    int colCount = Range.Columns.Count;
                    int rowCount = Range.Rows.Count;

                    List <iPOS.DTO.Tools.OBJ_TableColumnDTO> objList = await iPOS.BUS.Tools.OBJ_TableColumnBUS.GetTableColumnList(username, store_procedure);

                    if (objList != null && objList.Count > 0)
                    {
                        int count = 0;
                        for (int i = 1; i <= colCount; i++)
                        {
                            if (string.IsNullOrEmpty(Sheet.Cells[2, i].Value + ""))
                            {
                                break;
                            }
                            string tmp = Sheet.Cells[2, i].Value.ToString().ToLower().Trim();
                            if (string.IsNullOrEmpty(tmp))
                            {
                                break;
                            }
                            if (tmp != "stt" && tmp != "seq" && tmp != "$hidecolumn$" && tmp != "$deletecolumn$")
                            {
                                tmp = "@" + tmp;
                                var objs = (from obj in objList
                                            where obj.ColumnName.ToLower().Equals(tmp.ToLower())
                                            select obj).ToList();
                                if (objs.Count == 0)
                                {
                                    count++;
                                }
                            }
                        }
                        //result = count < 3;
                        result = count == 0;    //!= 0 is different all
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return(false);
            }
            finally
            {
                if (App != null)
                {
                    App.Quit();
                }
                GC.Collect();
                if (Range != null)
                {
                    Marshal.FinalReleaseComObject(Range);
                }
                if (Sheet != null)
                {
                    Marshal.FinalReleaseComObject(Sheet);
                }
                if (Book != null)
                {
                    //Book.Close(true, Missing, Missing);
                    Marshal.FinalReleaseComObject(Book);
                }
                if (App != null)
                {
                    Marshal.FinalReleaseComObject(App);
                }
            }

            return(result);
        }