Ejemplo n.º 1
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.º 2
0
        public timeAttRealtimeMasterModel master(timeAttRealModel value)
        {
            timeAttRealtimeMasterModel result = new timeAttRealtimeMasterModel();

            try
            {
                using (var context = new StandardCanEntities())
                {
                    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");
                    }

                    string sql = "select		convert(nvarchar(5), MD_ID) code ";
                    sql += " , md_name [text] ";
                    sql += " from MAS_DEPARTMENT ";
                    sql += " where md_status = 1 ";
                    sql += " order by md_name ";
                    result.department = context.Database.SqlQuery <dropdown>(sql).ToList();

                    sql         = "select		convert(nvarchar(5), MN_ID) code ";
                    sql        += " , mn_name [text] ";
                    sql        += " from MAS_NODE ";
                    sql        += " where mn_status = 1 ";
                    sql        += " order by mn_name ";
                    result.node = context.Database.SqlQuery <dropdown>(sql).ToList();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(result);
        }
Ejemplo n.º 3
0
 public IEnumerable <sp_timeatt_realtime_search_Result> search(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");
         }
         StandardCanEntities context = new StandardCanEntities();
         IEnumerable <sp_timeatt_realtime_search_Result> result = context.sp_timeatt_realtime_search
                                                                      (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).AsEnumerable();
         return(result);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Ejemplo n.º 4
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);
        }
        // POST: api/timeAttRealtime
        public HttpResponseMessage Post([FromBody] timeAttRealModel value)
        {
            if (value == null)
            {
                return(null);
            }
            JavaScriptSerializer js = new JavaScriptSerializer();

            timeAttRealService  service  = new timeAttRealService();
            HttpResponseMessage response = null;
            Object result = null;

            switch (value.method)
            {
            case "master":
                result = service.master(value);
                break;

            case "search":
                result = service.search(value);
                break;

            case "detail":
                result = service.detail(value);
                break;

            //case "exportFile":
            //    resultFile = service.exportFileWeb(value);
            //    break;

            //case "insert":
            //    result = service.insert(value);
            //    break;

            //case "update":
            //    result = service.update(value);
            //    break;

            //case "delete":
            //    result = service.delete(value);
            //    break;

            default:
                break;
            }

            if (value.method == "exportFile")
            {
                var resultFile = service.exportFileWeb(value);
                HttpResponseMessage resultExport = null;
                resultExport         = Request.CreateResponse(HttpStatusCode.OK);
                resultExport.Content = new ByteArrayContent(resultFile.FileContents);
                resultExport.Content.Headers.ContentDisposition          = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
                resultExport.Content.Headers.ContentDisposition.FileName = resultFile.FileDownloadName;
                return(resultExport);
            }

            string json = js.Serialize(result);

            response         = Request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
            return(response);
        }