private void GenerateBarcode(string barcode)
        {
            try
            {
                //


                var writer = new ZXing.BarcodeWriter
                {
                    Format = BarcodeFormat.CODE_128
                };
                Bitmap bitmap = writer.Write(barcode);

                usp_tblStatusMasterGetByType_Result result = InventoryEntities.usp_tblStatusMasterGetByType(8).FirstOrDefault();
                string sPath = result.statusDesc;


                using (MemoryStream Mmst = new MemoryStream())
                {
                    //bitm.Save("ms", ImageFormat.Jpeg);
                    bitmap.Save(sPath + barcode + ".png");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //method to save file for  Signature VanOffload
        public async Task <string> PostFileVanOffload()
        {
            try
            {
                Err.ErrorLog("PostFileVanOffload called");
                usp_tblStatusMasterGetByType_Result SignaturePath = InventoryEntities.usp_tblStatusMasterGetByType(15).FirstOrDefault();
                if (!Request.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                // string root = HttpContext.Current.Server.MapPath("~/Content");
                var provider = new MultipartFormDataStreamProvider(SignaturePath.statusDesc.ToString());


                StringBuilder sb = new StringBuilder(); // Holds the response body

                // Read the form data and return an async task.
                await Request.Content.ReadAsMultipartAsync(provider);

                // This illustrates how to get the form data.
                string filename = ""; int count = 0;
                foreach (var key in provider.FormData.AllKeys)
                {
                    foreach (var val in provider.FormData.GetValues(key))
                    {
                        sb.Append(string.Format("{0}: {1}\n", key, val));
                        if (count == 0)
                        {
                            filename = val;
                        }
                    }
                }

                // This illustrates how to get the file names for uploaded files.


                foreach (var file in provider.FileData)
                {
                    FileInfo fileInfo = new FileInfo(file.LocalFileName);
                    FileSystem.Rename(fileInfo.FullName, SignaturePath.statusDesc.ToString() + filename);
                    //sb.Append(string.Format("Uploaded file: {0} ({1} bytes)\n", fileInfo.Name, fileInfo.Length));
                }

                String[] lines = { "sucess sb string" };
                //      File.WriteAllLines(@"D:\IndoGhana\API\log.txt", lines);

                Err.ErrorLog("PostFileVanOffload called end");
                return("1");
            }
            catch (System.Exception e)
            {
                Err.ErrorLog("PostFileVanOffload Error:" + e.Message);
                return("0");
            }
        }
Exemplo n.º 3
0
        public async Task <string> PostFile()
        {
            // Check if the request contains multipart/form-data.
            //string result;
            //String[] lines = { "First line from file ", "Second line from file", "Third line from file" };
            //File.WriteAllLines(@"D:\IndoGhana\API\log.txt", lines);

            usp_tblStatusMasterGetByType_Result BarcodePath = InventoryEntities.usp_tblStatusMasterGetByType(8).FirstOrDefault();

            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root     = HttpContext.Current.Server.MapPath("~/Content");
            var    provider = new MultipartFormDataStreamProvider(BarcodePath.statusDesc.ToString());

            try
            {
                StringBuilder sb = new StringBuilder(); // Holds the response body

                // Read the form data and return an async task.
                await Request.Content.ReadAsMultipartAsync(provider);

                // This illustrates how to get the form data.
                string filename = ""; int count = 0;
                foreach (var key in provider.FormData.AllKeys)
                {
                    foreach (var val in provider.FormData.GetValues(key))
                    {
                        sb.Append(string.Format("{0}: {1}\n", key, val));
                        if (count == 0)
                        {
                            filename = val;
                        }
                    }
                }

                // This illustrates how to get the file names for uploaded files.


                foreach (var file in provider.FileData)
                {
                    FileInfo fileInfo = new FileInfo(file.LocalFileName);
                    FileSystem.Rename(fileInfo.FullName, BarcodePath.statusDesc.ToString() + filename);
                    //sb.Append(string.Format("Uploaded file: {0} ({1} bytes)\n", fileInfo.Name, fileInfo.Length));
                }

                //if (!String.IsNullOrEmpty(sb.ToString()))
                //{
                //    //File.AppendAllText(@"D:\IndoGhana\API\log.txt", sb.ToString());
                String[] lines = { "sucess sb string" };
                File.WriteAllLines(@"D:\IndoGhana\API\log.txt", lines);

                //}
                //else
                //{
                //    String[] lines = { "empty sb string", "Second line from file", "Third line from file" };
                //    File.WriteAllLines(@"D:\IndoGhana\API\log.txt", lines);
                //    //   File.AppendAllText(@"D:\IndoGhana\API\log.txt", "No key found");
                //}
                ////return new HttpResponseMessage()
                //{
                //    Content = new StringContent(sb.ToString())
                //};

                //    return "Successfully uploaded";
                return(sb.ToString());
            }
            catch (System.Exception e)
            {
                //return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
                //File.AppendAllText(@"D:\IndoGhana\API\log.txt", e.InnerException.ToString());
                //String[] lines = { "errror", "Second line from file", "Third line from file" };
                //File.WriteAllLines(@"D:\IndoGhana\API\log.txt", lines);
                return(e.InnerException.ToString());
            }
        }