private void btnSubmit_Click(object sender, EventArgs e)
        {
            txtOutput.Text = string.Empty;
            var result = validateWindow();

            if (!string.IsNullOrEmpty(result))
                MessageBox.Show(result, APPLICATION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);

            try
            {
                JsonPathModel model = new JsonPathModel
                {
                    SourceJson = string.Join(Environment.NewLine, txtJson.Lines),
                    Expressions = Array.ConvertAll(txtExpression.Text.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries), (s) => new JsonPathExpression { Expression = s })
                };

                var expressions = _presenter.ParseExpression(model, ScriptEvaluatorFactory.ScriptEvaluatorTypes.Json, new JsonValueSystem());

                foreach (var expression in expressions)
                {
                    if (!isFirstLine())
                        txtOutput.Text += Environment.NewLine + Environment.NewLine;

                    txtOutput.Text += string.Format("Output of {0} is: \r\n {1}\r\n", expression.Expression,
                        string.Join(Environment.NewLine + Environment.NewLine, expression.Nodes));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, APPLICATION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        public benefitsDataResultModel search(benefitsModel value)
        {
            benefitsDataResultModel result = new benefitsDataResultModel();

            result.message = new messageModel();
            try
            {
                using (StandardCanEntities context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }

                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(value);
                    context.interface_log.Add(new interface_log
                    {
                        data_log    = json,
                        module      = "Benefits_search",
                        update_date = DateTime.Now
                    });
                    context.SaveChanges();

                    var data = context.MAS_BENEFITS.Where(a => a.mb_title.Contains(value.title)).ToList();
                    result.benefitData = new List <benefitsModel>();
                    foreach (var item in data)
                    {
                        benefitsModel news = new benefitsModel();
                        news.id     = item.MB_ID.ToString();
                        news.title  = item.mb_title;
                        news.detail = item.mb_detail;
                        news.url    = !String.IsNullOrEmpty(item.mb_link_url) ? _Gapi.GGC_VAL + jsonPath.benefits + item.mb_link_url : null;
                        result.benefitData.Add(news);
                    }

                    result.message.status  = "S";
                    result.message.message = "Success";
                }
            }
            catch (Exception ex)
            {
                result.message.status  = "E";
                result.message.message = ex.Message.ToString();
            }
            return(result);
        }
Ejemplo n.º 3
0
        public dashBoardModel search(dashBoardModel value)
        {
            dashBoardModel result = new dashBoardModel();

            result.message = new messageModel();
            try
            {
                using (StandardCanEntities context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(value);
                    context.interface_log.Add(new interface_log
                    {
                        data_log    = json,
                        module      = "dashBoard",
                        update_date = DateTime.Now
                    });
                    context.SaveChanges();

                    var data = context.IMAGE_SLIDE.Where(a => a.is_status == 1).ToList().OrderBy(a => a.is_order_by).ToList();
                    result.imgList = new List <dashBoardImg>();
                    foreach (var item in data)
                    {
                        dashBoardImg news = new dashBoardImg();
                        string       path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.imageSlide),
                                                         Path.GetFileName(item.is_url_image));
                        byte[] bytes = File.ReadAllBytes(path);
                        news.base64 = Convert.ToBase64String(bytes);
                        result.imgList.Add(news);
                    }

                    result.message.status  = "S";
                    result.message.message = "Success";
                }
            }
            catch (Exception ex)
            {
                result.message.status  = "E";
                result.message.message = ex.Message.ToString();
            }
            return(result);
        }
Ejemplo n.º 4
0
        public FileContentResult exportFileWeb(timeAttRealModel value)
        {
            try
            {
                if (String.IsNullOrEmpty(value.user_id))
                {
                    throw new Exception("Unauthorized Access");
                }
                var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }
                using (var context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }

                    string out_put_dir = System.AppDomain.CurrentDomain.BaseDirectory + jsonPath.timeAttRealtime;
                    Directory.CreateDirectory(out_put_dir);
                    string filePath = out_put_dir + value.fileName;
                    var    microsoftDateFormatSettings = new JsonSerializerSettings
                    {
                        DateParseHandling  = DateParseHandling.None,
                        DateFormatHandling = DateFormatHandling.IsoDateFormat,
                        Formatting         = Formatting.Indented,
                    };
                    using (StreamWriter writer = new StreamWriter(filePath, true))
                    {
                        var v_date_from = String.IsNullOrEmpty(value.start_date) ? "" : DateTime.ParseExact(value.start_date, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy");
                        var v_date_to   = String.IsNullOrEmpty(value.stop_date) ? "" : DateTime.ParseExact(value.stop_date, "yyyy-MM-dd", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy");

                        IEnumerable <sp_report_timeatt_v2_Result> dataList = context.sp_report_timeatt_v2(value.start_date, value.stop_date, value.emp_code_from, value.emp_code_to, value.depart_from, value.depart_to, value.fname, value.lname, value.node_from, value.node_to, userId).ToList();
                        foreach (var item in dataList)
                        {
                            writer.WriteLine(item.emp_code + "  " + item.type1 + " " + item.tar_date + " " + item.tar_time + " " + item.type2);
                        }
                    }

                    var               file      = System.IO.Path.Combine(out_put_dir, value.fileName);
                    byte[]            fileBytes = System.IO.File.ReadAllBytes(file);
                    FileContentResult result    = new FileContentResult(fileBytes, "application/octet-stream");
                    result.FileDownloadName = value.fileName;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Ejemplo n.º 5
0
        public messageModel getUploadFile(employeeModel value)
        {
            messageModel result = new messageModel();

            try
            {
                using (StandardCanEntities context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var empDetail = context.EMP_PROFILE.SingleOrDefault(a => a.emp_code == value.emp_code);
                    if (empDetail != null)
                    {
                        string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.employee),
                                                   Path.GetFileName(empDetail.emp_image));
                        byte[] bytes = File.ReadAllBytes(path);
                        result.value = Convert.ToBase64String(bytes);
                    }
                    else
                    {
                        throw new Exception("Data not found");
                    }
                }

                result.status  = "S";
                result.message = "";
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }
            return(result);
        }
Ejemplo n.º 6
0
        public IEnumerable <JsonPathExpression> ParseExpression(JsonPathModel model, ScriptEvaluatorFactory.ScriptEvaluatorTypes evaluatorType = ScriptEvaluatorFactory.ScriptEvaluatorTypes.Basic, IJsonPathValueSystem valueSystem = null)
        {
            IList <JsonPathExpression> result = new List <JsonPathExpression>(model.Expressions.Count());
            var json = JsonConvert.DeserializeObject(model.SourceJson);

            var context = new JsonPathContext
            {
                ScriptEvaluator = new JsonPathScriptEvaluator(ScriptEvaluatorFactory.Create(evaluatorType).EvaluateScript),
                ValueSystem     = valueSystem
            };

            foreach (JsonPathExpression expression in model.Expressions)
            {
                var nodes = context.SelectNodes(json, expression.Expression);
                Array.Copy(nodes, expression.Nodes.ToArray(), nodes.Length);
                result.Add(expression);
            }

            return(result.AsEnumerable());
        }
Ejemplo n.º 7
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            txtOutput.Text = string.Empty;
            var result = validateWindow();

            if (!string.IsNullOrEmpty(result))
            {
                MessageBox.Show(result, APPLICATION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                JsonPathModel model = new JsonPathModel
                {
                    SourceJson  = string.Join(Environment.NewLine, txtJson.Lines),
                    Expressions = Array.ConvertAll(txtExpression.Text.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries), (s) => new JsonPathExpression {
                        Expression = s
                    })
                };

                var expressions = _presenter.ParseExpression(model);

                foreach (var expression in expressions)
                {
                    if (!isFirstLine())
                    {
                        txtOutput.Text += Environment.NewLine + Environment.NewLine;
                    }

                    var nodes = expression.Nodes.Select(node => new { Path  = node.Path,
                                                                      Value = JsonConvert.Serialize(node.Value) });

                    txtOutput.Text += string.Format("Output of {0} is: \r\n {1}\r\n", expression.Expression,
                                                    string.Join(Environment.NewLine + Environment.NewLine, nodes));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, APPLICATION_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 8
0
        public timeAttRealtimeDetailModel detail(timeAttRealModel value)
        {
            timeAttRealtimeDetailModel result = new timeAttRealtimeDetailModel();

            try
            {
                using (var context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }

                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    result.imgList = new List <string>();
                    var attRealtime = context.TIME_ATT_REALTIME.SingleOrDefault(a => a.TAR_ID.ToString() == value.id);
                    if (attRealtime != null)
                    {
                        var attRealtimeImg = context.TIME_ATT_IMAGE.Where(a => a.TAR_ID == attRealtime.TAR_ID).ToList();
                        if (!Directory.Exists(Path.GetDirectoryName(HostingEnvironment.MapPath("~" + jsonPath.timeAttReal))))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(HostingEnvironment.MapPath("~" + jsonPath.timeAttReal)));
                        }
                        DirectoryInfo di = new DirectoryInfo(HostingEnvironment.MapPath("~" + jsonPath.timeAttReal));

                        foreach (var item in attRealtimeImg)
                        {
                            foreach (FileInfo files in di.GetFiles())
                            {
                                if (files.Name == item.tari_image)
                                {
                                    string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.timeAttReal),
                                                               Path.GetFileName(item.tari_image));

                                    byte[] bytes  = File.ReadAllBytes(path);
                                    var    base64 = Convert.ToBase64String(bytes);
                                    result.imgList.Add(base64);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Data not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(result);
        }
Ejemplo n.º 9
0
        public messageModel insert(imageSlideModel value)
        {
            messageModel result = new messageModel();

            try
            {
                using (var context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(value);
                    context.interface_log.Add(new interface_log
                    {
                        data_log    = json,
                        module      = "ImageSlide_insert",
                        update_date = DateTime.Now
                    });
                    context.SaveChanges();

                    var         dt   = DateTime.Now;
                    IMAGE_SLIDE news = new IMAGE_SLIDE();
                    news.is_status = 1;
                    if (value.img != null)
                    {
                        string[] img       = value.img.Split(',');
                        var      imgBase64 = img.Count() > 1 ? img[1] : img[0];
                        byte[]   imgbyte   = Convert.FromBase64String(imgBase64);
                        var      guId      = Guid.NewGuid().ToString();
                        var      fileName  = guId + ".JPG";
                        string   path      = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.imageSlide),
                                                          Path.GetFileName(fileName));
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            stream.Write(imgbyte, 0, imgbyte.Length);
                        }
                        news.is_url_image   = fileName;
                        news.is_url_link    = value.url;
                        news.is_update_date = dt;
                        news.is_update_by   = Convert.ToInt32(userId);
                        var lastOrder = context.IMAGE_SLIDE.OrderByDescending(u => u.is_order_by).FirstOrDefault();
                        news.is_order_by = (short?)(lastOrder != null ? (Convert.ToInt32(lastOrder.is_order_by) + 1) : 0);
                        context.IMAGE_SLIDE.Add(news);
                        context.SaveChanges();
                    }
                    else
                    {
                        throw new Exception("Image not Found");
                    }

                    result.status  = "S";
                    result.message = "Success";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Ejemplo n.º 10
0
        public messageModel delete(imageSlideModel value)
        {
            messageModel result = new messageModel();

            try
            {
                using (var context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(value);
                    context.interface_log.Add(new interface_log
                    {
                        data_log    = json,
                        module      = "ImageSlide_delete",
                        update_date = DateTime.Now
                    });
                    context.SaveChanges();

                    var news = context.IMAGE_SLIDE.SingleOrDefault(a => a.IS_ID.ToString() == value.id);
                    if (news != null)
                    {
                        DirectoryInfo di = new DirectoryInfo(HostingEnvironment.MapPath("~" + jsonPath.imageSlide));
                        foreach (FileInfo files in di.GetFiles())
                        {
                            if (files.Name == news.is_url_image)
                            {
                                files.Delete();
                            }
                        }
                        context.IMAGE_SLIDE.Remove(news);
                        context.SaveChanges();

                        result.status  = "S";
                        result.message = "Success";
                    }
                    else
                    {
                        result.status  = "E";
                        result.message = "Data not Found";
                    }
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Ejemplo n.º 11
0
        public messageModel uploadFile(employeeModel value)
        {
            messageModel result = new messageModel();

            try
            {
                using (var context = new StandardCanEntities())
                {
                    var           dt       = DateTime.Now;
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(value);
                    context.interface_log.Add(new interface_log
                    {
                        data_log    = json,
                        module      = "Employee_uploadFile",
                        update_date = dt
                    });
                    context.SaveChanges();
                    if (value.img != null)
                    {
                        string[] img       = value.img.Split(',');
                        var      imgBase64 = img.Count() > 1 ? img[1] : img[0];
                        byte[]   imgbyte   = Convert.FromBase64String(imgBase64);
                        var      guId      = Guid.NewGuid().ToString();
                        var      fileName  = guId + ".JPG";
                        string   path      = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.employee),
                                                          Path.GetFileName(fileName));
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            stream.Write(imgbyte, 0, imgbyte.Length);
                        }
                        var empDetail = context.EMP_PROFILE.SingleOrDefault(a => a.emp_code == value.emp_code);
                        if (empDetail != null)
                        {
                            empDetail.emp_image = fileName;
                            context.SaveChanges();
                        }
                        else
                        {
                            throw new Exception("Data not found");
                        }
                    }
                }

                result.status  = "S";
                result.message = "";
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }
            return(result);
        }
Ejemplo n.º 12
0
        public messageModel tab_behavior_export(employeeModel value)
        {
            messageModel result = new messageModel();

            StandardCanEntities context = new StandardCanEntities();

            try
            {
                var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                JsonPathModel jsonPath = new JsonPathModel();
                if (_Gpath != null)
                {
                    jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                }

                if (String.IsNullOrEmpty(value.user_id))
                {
                    throw new Exception("Unauthorized Access");
                }
                var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }

                var dataList = context.sp_emp_profile_tabbehavior_search_v2(value.emp_code).ToList();

                if (dataList != null && dataList.Count() > 0)
                {
                    string file_name = string.Format("emp_behavior_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss"));
                    string file_path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileExport", file_name);

                    string file_path_folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileExport");
                    bool   exists           = System.IO.Directory.Exists(file_path_folder);

                    if (!exists)
                    {
                        var fileCreate = System.IO.Directory.CreateDirectory(file_path_folder);
                    }

                    FileInfo excelFile = new FileInfo(file_path);
                    using (ExcelPackage excel = new ExcelPackage(excelFile))
                    {
                        string         sheetName  = "data";
                        int            row        = 1;
                        ExcelWorksheet wsTemplate = excel.Workbook.Worksheets.Add(sheetName);
                        wsTemplate.Cells[row, 1].Value = "ลำดับ";
                        wsTemplate.Cells[row, 2].Value = "ปี";
                        wsTemplate.Cells[row, 3].Value = "วันที่";
                        wsTemplate.Cells[row, 4].Value = "รายละเอียด";
                        wsTemplate.Cells[row, 5].Value = "คะแนน";

                        row++;
                        foreach (var item in dataList)
                        {
                            wsTemplate.Cells[row, 1].Value = item.no;
                            wsTemplate.Cells[row, 2].Value = item.year;
                            wsTemplate.Cells[row, 3].Value = item.date;
                            wsTemplate.Cells[row, 4].Value = item.detail;
                            wsTemplate.Cells[row, 5].Value = item.score;
                            row++;
                        }

                        wsTemplate.Cells.AutoFitColumns();
                        excel.Save();
                    }

                    result.status  = "S";
                    result.message = "Success";
                    result.value   = _Gapi.GGC_VAL + jsonPath.fileExport + file_name;
                }
                else
                {
                    result.status  = "E";
                    result.message = "not found data!";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Ejemplo n.º 13
0
        public messageModel save(projectCourseModel value)
        {
            messageModel result = new messageModel();

            try
            {
                if (String.IsNullOrEmpty(value.user_id))
                {
                    throw new Exception("Unauthorized Access");
                }
                var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }

                System.Data.Entity.Core.Objects.ObjectParameter myOutputParamInt = new System.Data.Entity.Core.Objects.ObjectParameter("r_id", typeof(Int32));

                using (var context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }

                    if (!String.IsNullOrEmpty(value.file_base64))
                    {
                        string[] doc       = value.file_base64.Split(',');
                        var      imgBase64 = doc.Count() > 1 ? doc[1] : doc[0];
                        byte[]   imgbyte   = Convert.FromBase64String(imgBase64);
                        var      guId      = Guid.NewGuid().ToString();
                        var      fileName  = guId + ".PDF";
                        string   path      = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.projectCourse),
                                                          Path.GetFileName(fileName));
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        DirectoryInfo di = new DirectoryInfo(HostingEnvironment.MapPath("~" + jsonPath.projectCourse));
                        foreach (FileInfo files in di.GetFiles())
                        {
                            if (files.Name == value.file_name)
                            {
                                files.Delete();
                            }
                        }
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            stream.Write(imgbyte, 0, imgbyte.Length);
                        }
                        value.file_name = fileName;
                    }
                    else if (String.IsNullOrEmpty(value.file_url))
                    {
                        string path = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.projectCourse));
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        DirectoryInfo di = new DirectoryInfo(HostingEnvironment.MapPath("~" + jsonPath.projectCourse));
                        foreach (FileInfo files in di.GetFiles())
                        {
                            if (files.Name == value.file_name)
                            {
                                files.Delete();
                            }
                        }
                        value.file_name = null;
                    }

                    int ret = context.sp_project_course_save_v2(value.id, value.project_id, value.course_id, value.course_name, value.formula_id, value.location_id, value.expert_id, value.file_name, value.file_base64, value.remark, value.score1, value.score2, value.score3, value.score4, value.score5, userId, value.status_id, myOutputParamInt);
                }


                if (myOutputParamInt.Value != null)
                {
                    int r_id = Convert.ToInt32(myOutputParamInt.Value);
                    result.status  = "S";
                    result.message = "";
                    result.value   = r_id.ToString();
                }
                else
                {
                    result.status  = "E";
                    result.message = "";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Ejemplo n.º 14
0
        public messageModel insert(newsModel value)
        {
            messageModel result = new messageModel();

            try
            {
                using (var context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(value);
                    context.interface_log.Add(new interface_log
                    {
                        data_log    = json,
                        module      = "News_insert",
                        update_date = DateTime.Now
                    });
                    context.SaveChanges();

                    var  dt   = DateTime.Now;
                    NEWS news = new NEWS();
                    news.nw_type = value.newsTypeId != null?Convert.ToInt32(value.newsTypeId) : (int?)null;

                    news.nw_topic  = value.topic;
                    news.nw_detail = value.detail;
                    news.nw_status = 1;

                    if (news.nw_type == 1 || news.nw_type == 2)
                    {
                        if (value.img != null)
                        {
                            string[] img       = value.img.Split(',');
                            var      imgBase64 = img.Count() > 1 ? img[1] : img[0];
                            byte[]   imgbyte   = Convert.FromBase64String(imgBase64);
                            var      guId      = Guid.NewGuid().ToString();
                            var      fileName  = guId + ".JPG";
                            string   path      = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.news),
                                                              Path.GetFileName(fileName));
                            if (!Directory.Exists(Path.GetDirectoryName(path)))
                            {
                                Directory.CreateDirectory(Path.GetDirectoryName(path));
                            }
                            using (var stream = new FileStream(path, FileMode.Create))
                            {
                                stream.Write(imgbyte, 0, imgbyte.Length);
                            }
                            news.nw_image = fileName;
                        }
                    }
                    else if (news.nw_type == 3)
                    {
                        news.nw_vdo = value.urlVdo;
                    }

                    news.nw_date        = dt;
                    news.nw_update_by   = Convert.ToInt32(userId);
                    news.nw_update_date = dt;
                    context.NEWS.Add(news);
                    context.SaveChanges();

                    result.status  = "S";
                    result.message = "Success";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }
Ejemplo n.º 15
0
        public newsDataResultModel search(newsModel value)
        {
            newsDataResultModel result = new newsDataResultModel();

            result.message = new messageModel();
            try
            {
                using (StandardCanEntities context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }

                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(value);
                    context.interface_log.Add(new interface_log
                    {
                        data_log    = json,
                        module      = "News_search",
                        update_date = DateTime.Now
                    });
                    context.SaveChanges();

                    var data = context.NEWS.Where(a => a.nw_topic.Contains(value.topic)).ToList();
                    result.newsData = new List <newsModel>();
                    foreach (var item in data)
                    {
                        newsModel news = new newsModel();
                        news.id         = item.NW_ID.ToString();
                        news.newsTypeId = item.nw_type.ToString();
                        if (news.newsTypeId == "1")
                        {
                            news.newsTypeName = "ข่าวสาร";
                        }
                        else if (news.newsTypeId == "2")
                        {
                            news.newsTypeName = "กิจกรรม";
                        }
                        else if (news.newsTypeId == "3")
                        {
                            news.newsTypeName = "vdo";
                        }
                        news.topic  = item.nw_topic;
                        news.detail = item.nw_detail;
                        news.url    = !String.IsNullOrEmpty(item.nw_image) ? _Gapi.GGC_VAL + jsonPath.news + item.nw_image : null;
                        news.urlVdo = item.nw_vdo;
                        result.newsData.Add(news);
                    }

                    result.message.status  = "S";
                    result.message.message = "Success";
                }
            }
            catch (Exception ex)
            {
                result.message.status  = "E";
                result.message.message = ex.Message.ToString();
            }
            return(result);
        }
Ejemplo n.º 16
0
        public messageModel insert(benefitsModel value)
        {
            messageModel result = new messageModel();

            try
            {
                using (var context = new StandardCanEntities())
                {
                    var           _Gapi    = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "API_PATH");
                    var           _Gpath   = context.MAS_GLOBAL_CONFIG.SingleOrDefault(x => x.GGC_KEY == "FILE_PATH");
                    JsonPathModel jsonPath = new JsonPathModel();
                    if (_Gpath != null)
                    {
                        jsonPath = (JsonPathModel)Newtonsoft.Json.JsonConvert.DeserializeObject(_Gpath.GGC_VAL, typeof(JsonPathModel));
                    }
                    if (String.IsNullOrEmpty(value.user_id))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    var userId = JwtHelper.GetUserIdFromToken(value.user_id);
                    if (String.IsNullOrEmpty(userId))
                    {
                        throw new Exception("Unauthorized Access");
                    }
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string json             = js.Serialize(value);
                    context.interface_log.Add(new interface_log
                    {
                        data_log    = json,
                        module      = "Benefits_insert",
                        update_date = DateTime.Now
                    });
                    context.SaveChanges();

                    var          dt       = DateTime.Now;
                    MAS_BENEFITS benefits = new MAS_BENEFITS();
                    benefits.mb_title  = value.title;
                    benefits.mb_detail = value.detail;

                    if (value.doc != null)
                    {
                        string[] doc       = value.doc.Split(',');
                        var      docBase64 = doc.Count() > 1 ? doc[1] : doc[0];
                        byte[]   imgbyte   = Convert.FromBase64String(docBase64);
                        var      guId      = Guid.NewGuid().ToString();
                        var      fileName  = guId + ".PDF";
                        string   path      = Path.Combine(HostingEnvironment.MapPath("~" + jsonPath.benefits),
                                                          Path.GetFileName(fileName));
                        if (!Directory.Exists(Path.GetDirectoryName(path)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(path));
                        }
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            stream.Write(imgbyte, 0, imgbyte.Length);
                        }
                        benefits.mb_link_url = fileName;
                    }
                    context.MAS_BENEFITS.Add(benefits);
                    context.SaveChanges();

                    result.status  = "S";
                    result.message = "Success";
                }
            }
            catch (Exception ex)
            {
                result.status  = "E";
                result.message = ex.Message.ToString();
            }

            return(result);
        }