public ActionResult bulk(HttpPostedFileBase FileUpload, string pallet_name) { string path = ""; DataTable dt = new DataTable(); //check we have a file if (FileUpload.ContentLength > 0) { //Workout our file path string fileName = Path.GetFileName(FileUpload.FileName); path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); try { FileUpload.SaveAs(path); List <string> temp_line = new List <string>(); using (StringReader reader = new StringReader(System.IO.File.ReadAllText(path))) { string line = null; while ((line = reader.ReadLine()) != null) { if (!temp_line.Contains(line)) { temp_line.Add(line); } } } using (StreamWriter writer = new StreamWriter(System.IO.File.Open(path, FileMode.Create))) foreach (string r in temp_line) { var updateQuery = new pallet(); updateQuery.ictags = int.Parse(r); updateQuery.pallet_name = pallet_name; db.pallet.Add(updateQuery); } var palletmaster = new pallet_master(); palletmaster.pallet_id = pallet_name; db.pallet_master.Add(palletmaster); db.SaveChanges(); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } catch (Exception ex) { if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } //Catch errors TempData["message"] = ex.ToString(); } } return(RedirectToAction("bulk")); }
public ActionResult Create([Bind(Include = "ictags,pallet_name,type,note")] pallet pallet) { if (ModelState.IsValid) { db.pallet.Add(pallet); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(pallet)); }
public ActionResult Create([Bind(Include = "station_name,station_dropdown_value,description")] station_setting station_setting) { if (ModelState.IsValid) { db.station_setting.Add(station_setting); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(station_setting)); }
public ActionResult Create([Bind(Include = "channel_name,background,type,full_name")] setting setting) { if (ModelState.IsValid) { db.setting.Add(setting); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(setting)); }
public ActionResult Create([Bind(Include = "ictag,time,serial,brand,model,cpu,hdd,ram,optical_drive,location")] discovery discovery) { if (ModelState.IsValid) { db.discovery.Add(discovery); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(discovery)); }
public ActionResult Create([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName,department")] aspnetusers aspNetUsers) { if (ModelState.IsValid) { db.aspnetusers.Add(aspNetUsers); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aspNetUsers)); }
public ActionResult Create([Bind(Include = "ictag,time,serial,brand,model,cpu,hdd,ram,optical_drive,location,pallet,pre_coa,refurbisher")] rediscovery rediscovery) { if (ModelState.IsValid) { db.rediscovery.Add(rediscovery); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rediscovery)); }
public ActionResult Create([Bind(Include = "user_name,work_status,pw,role")] users users) { if (ModelState.IsValid) { db.users.Add(users); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(users)); }
public ActionResult Create([Bind(Include = "time,manu,monitor_ID,serial,size,resou,model,ictag")] monitor_log monitor_log) { if (ModelState.IsValid) { db.monitor_log.Add(monitor_log); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(monitor_log)); }
public ActionResult Create([Bind(Include = "ictag,shipdate,status,order_id,order_num,row_id,store_id,sku")] ship_log ship_log) { if (ModelState.IsValid) { db.ship_log.Add(ship_log); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ship_log)); }
//function for bottom 3 windows coas info from index2 page public JsonResult update_counter(int count) { var updateQuery = new asset_tag_counter() { Company = "interconnection", count = count }; db.asset_tag_counter.Attach(updateQuery); db.Entry(updateQuery).Property(x => x.count).IsModified = true; db.SaveChanges(); return(Json(JsonRequestBehavior.AllowGet)); }
public ActionResult edit_discovery_asset(string hdd, string ram, string sku, string pre_coa, string refurbisher, string asset) { var temp_asset = int.Parse(asset); var discovery = db.discovery.Where(s => s.ictag == temp_asset).FirstOrDefault <discovery>(); // var discovery = new discovery(); discovery.hdd = hdd; discovery.ram = ram; db.discovery.AddOrUpdate(discovery); db.SaveChanges(); return(View("edit_asset", this)); }
public JsonResult ts_ship_stock(string[] asset) { string message = ""; //format the tsg sku to the ss format // channel = channel.Replace("TSG_", "HW-"); for (int i = 0; i < asset.Length; i++) { try { string temp_asset = asset[i]; var db = new db_a094d4_icdbEntities1(); var update_asset = db.ts_stock.Where(s => s.ictag == temp_asset).First(); update_asset.status = "Shipped"; db.SaveChanges(); message += "<p style='color:green'>" + asset[i] + " Sucessfully Marked as Shipped</p>"; } catch (Exception e) { message += "<p style='color:red'>" + asset[i] + e.InnerException.InnerException.Message + "</p>"; } } db.Dispose(); return(Json(message, JsonRequestBehavior.AllowGet)); }
public JsonResult remove_ts_stock(string asset, string sku) { string message = ""; try { var ts_stock = new ts_stock { ictag = asset }; db.ts_stock.Attach(ts_stock); db.ts_stock.Remove(ts_stock); db.SaveChanges(); message = "Asset " + asset + " Removed"; } catch (Exception e) { message = "Error"; } return(Json(message, JsonRequestBehavior.AllowGet)); }
//add ts stock from production public JsonResult ts_add_stock(string[] asset) { string message = ""; string current_asset = ""; //format the tsg sku to the ss format // channel = channel.Replace("TSG_", "HW-"); for (int i = 0; i < asset.Length; i++) { string temp_asset = asset[i]; var db = new db_a094d4_icdbEntities1(); var exisit = (from t in db.ts_stock where t.ictag == temp_asset select t).FirstOrDefault(); if (exisit == null) { int int_asset = int.Parse(temp_asset); var channel = (from t in db.rediscovery where t.ictag == int_asset select t.pallet).FirstOrDefault(); if (!channel.Contains("TSG_")) { message += "<p style='color:red'>" + asset[i] + " has a non-TechSoup SKU</p>"; continue; } channel = channel.Replace("TSG_", "HW-"); ts_stock ts = new ts_stock(); ts.ictag = temp_asset; current_asset = temp_asset; ts.sku = channel; ts.status = "Ready_for_Shipping"; db.ts_stock.Add(ts); db.SaveChanges(); message += "<p style='color:green'>" + asset[i] + " Sucessfully Added to " + channel + "</p>"; } else { message += "<p style='color:red'>" + asset[i] + " Failed to Import (possible duplicate entry)</p>"; } } db.Dispose(); return(Json(message, JsonRequestBehavior.AllowGet)); }
public ActionResult Index(int?asset, string pre_coa, string product, DymoViewModel model, string myList) { if (string.IsNullOrEmpty(pre_coa) == true) { pre_coa = "00999-999-000-999"; } ViewBag.user = User.Identity.GetUserName(); ViewBag.channel = myList; ViewBag.pre_coa = pre_coa; ViewBag.pallet = product; ViewBag.asset = asset; ViewBag.time = DateTime.Now; var current_machine = (from m in db.rediscovery where m.ictag == asset select m).ToList(); // start update query var update = db.rediscovery.Single(u => u.ictag == asset); update.pre_coa = pre_coa; update.pallet = product; update.location = myList; update.refurbisher = User.Identity.GetUserName(); db.SaveChanges(); //end update query //iterate asset obj foreach (var item in current_machine) { ViewBag.CPU = item.cpu; ViewBag.HDD = item.hdd + " GB"; int temp_ram = int.Parse(item.ram); temp_ram = temp_ram / 1000; ViewBag.Ram = temp_ram + " GB"; ViewBag.Model = item.model; ViewBag.Serial = item.serial; } var channel_list = db.label_menu .Select(p => p.name) .Distinct().ToList(); SelectList list = new SelectList(channel_list); ViewBag.myList = list; return(View()); }
// GET: /Manage/palletmanager // [HttpPost] public ActionResult createPallet() { db_a094d4_icdbEntities1 db = new db_a094d4_icdbEntities1(); var data = (from p in db.pallet_master select new Models.inventoryManageViewModel { pallet = p.pallet_id, }); SelectList list = new SelectList(data, "pallet", "pallet"); ViewBag.Roles = list; ViewBag.data = data; //Loop through the forms for (int i = 0; i <= Request.Form.Count; i++) { var ictags = Request.Form["ictag[" + i + "]"]; var pallet_name = Request.Form["pallet_name[" + i + "]"]; var note = Request.Form["note[" + i + "]"]; if ((ictags != null) && (pallet_name != null)) { db.pallet.Add(new pallet { ictags = int.Parse(ictags), pallet_name = pallet_name, note = note }); db.SaveChanges(); } } return(View()); }
//process the item in custom fields public void count_item(shipstation_log entry) { try { var write_table = new ship_log(); if (string.IsNullOrEmpty(entry.custom_field_2)) { } else { try { string[] lines = entry.custom_field_2.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); lines = lines.Where(x => !string.IsNullOrEmpty(x)).ToArray(); foreach (var item in lines) { using (db_a094d4_icdbEntities1 db = new db_a094d4_icdbEntities1()) { var exisit = (from t in db.ship_log where t.ictag == item select t).SingleOrDefault(); if (exisit == null) { write_table.ictag = item; write_table.order_id = entry.order_id; write_table.order_num = entry.order_num; write_table.shipdate = entry.shipment_date; write_table.sku = entry.sku; write_table.status = entry.status; write_table.store_id = entry.store_id; db.ship_log.Add(write_table); db.SaveChanges(); } var update = db.ts_stock.Where(s => s.ictag == item).FirstOrDefault(); if (update != null) { update.status = "Shipped"; update.update_time = DateTime.Now; using (var dbCtx = new db_a094d4_icdbEntities1()) { //Mark entity as modified dbCtx.Entry(update).State = System.Data.Entity.EntityState.Modified; //call SaveChanges dbCtx.SaveChanges(); } } } } } catch { entry.custom_field_2 = ""; } } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
public async Task get_order_detail(int orderID) { var bb = 0; Thread.Sleep(1700); //try { var baseAddress = new Uri("https://ssapi.shipstation.com/"); db_a094d4_icdbEntities1 db = new db_a094d4_icdbEntities1(); using (var httpClient = new HttpClient { BaseAddress = baseAddress }) { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "Basic ZmU3YzE2MGMyZjE0NDc1ZDljNWQ0ZWI2ZmMzYmRhOWU6YzRiM2RhMjlkZWZlNDgyOWJlZmRlYTExNmU1N2Q5ZTY="); using (var response = await httpClient.GetAsync("orders/" + orderID + "")) { string responseData = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <Models.ShipStation_orderID.Rootobject>(responseData); for (int i = 0; i < result.items.Length; i++) { var write_table = new shipstation_log(); if (result.advancedOptions.customField1 == null) { result.advancedOptions.customField1 = ""; } if (result.advancedOptions.customField2 == null) { result.advancedOptions.customField2 = ""; } if (result.advancedOptions.customField3 == null) { result.advancedOptions.customField3 = ""; } write_table.sku = result.items[i].sku; write_table.store_id = result.advancedOptions.storeId; write_table.item_name = result.items[i].name; write_table.item_qty = result.items[i].quantity; write_table.item_url = result.items[i].imageUrl; write_table.custom_field_1 = result.advancedOptions.customField1.ToString(); write_table.custom_field_2 = result.advancedOptions.customField2.ToString(); write_table.custom_field_3 = result.advancedOptions.customField3.ToString(); write_table.order_id = orderID; write_table.order_num = result.orderNumber; write_table.status = result.orderStatus; if (result.shipDate == null) { write_table.shipment_date = null; } else { write_table.shipment_date = DateTime.Parse(result.shipDate); } db.shipstation_log.Add(write_table); db.SaveChanges(); Debug.WriteLine(bb++); count_item(write_table); } } } //} //catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) //{ // Exception raise = dbEx; // foreach (var validationErrors in dbEx.EntityValidationErrors) // { // foreach (var validationError in validationErrors.ValidationErrors) // { // string message = string.Format("{0}:{1}", // validationErrors.Entry.Entity.ToString(), // validationError.ErrorMessage); // // raise a new exception nesting // // the current instance as InnerException // raise = new InvalidOperationException(message, raise); // } // } // throw raise; //} }
public ActionResult fetch_rma() { var rma_list = search_rma(); foreach (var item in rma_list) { try { var rma = new rma(); rma.ictag = item.IC_Barcodes__c; if (!string.IsNullOrEmpty(item.IC_Barcodes__c) && item.IC_Barcodes__c.Contains("\n")) { string[] lines = item.IC_Barcodes__c.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); for (int i = 0; i < lines.Length; i++) { rma = new rma(); var ar_temp_ictag = int.Parse(lines[i]); rma.ictag = lines[i]; rma.id = item.Id; rma.resolution_code = item.Return_Resolution__c; rma.case_number = item.CaseNumber; rma.description = item.Description; rma.channel = item.Channel__c; rma.date_requested = item.CreatedDate; rma.production_finding = item.Production_Findings__c; rma.rma_number = item.RMA_number__c; var ar_serial = (from t in db.discovery where t.ictag == ar_temp_ictag select t.serial).FirstOrDefault(); rma.serial = ar_serial; db.rma.Add(rma); db.SaveChanges(); } continue; } int temp_ictag = 0; var sucess = int.TryParse(item.IC_Barcodes__c, out temp_ictag); if (sucess == false) { continue; } rma.id = item.Id; rma.description = item.Description; rma.resolution_code = item.Return_Resolution__c; rma.channel = item.Channel__c; rma.date_requested = item.CreatedDate; rma.case_number = item.CaseNumber; rma.production_finding = item.Production_Findings__c; rma.rma_number = item.RMA_number__c; var serial = (from t in db.discovery where t.ictag == temp_ictag select t.serial).FirstOrDefault(); rma.serial = serial; db.rma.Add(rma); db.SaveChanges(); } catch { continue; } } return(View()); }
//add new database entry for discover data public ActionResult insert_asset(int asset, string brand, string model, string refrub, string download, string cpu_brand, string cpu_type, string cpu_speed, string ram, string hdd, string serial) { var cpu = cpu_brand + " " + cpu_type + " " + cpu_speed; var xml = mrm_xml(asset.ToString(), brand, model, hdd, ram, serial, cpu); var db = new db_a094d4_icdbEntities1(); var exisit = (from t in db.discovery where t.ictag == asset select t).ToList(); if (exisit.Count == 0) { using (db as db_a094d4_icdbEntities1) { var new_entry = new discovery(); new_entry.brand = brand; new_entry.cpu = cpu; new_entry.hdd = hdd; new_entry.ictag = asset; new_entry.location = null; new_entry.model = model; new_entry.optical_drive = null; new_entry.ram = ram; new_entry.serial = serial; new_entry.time = DateTime.Now; db.discovery.Add(new_entry); db.SaveChanges(); TempData["message"] = "Data Imported"; } if (refrub == "on") { using (var db2 = new db_a094d4_icdbEntities1()) { var new_entry = new rediscovery(); new_entry.brand = brand; new_entry.cpu = cpu; new_entry.hdd = hdd; new_entry.ictag = asset; new_entry.location = null; new_entry.model = model; new_entry.optical_drive = null; new_entry.ram = ram; new_entry.serial = serial; new_entry.time = DateTime.Now; db2.rediscovery.Add(new_entry); db2.SaveChanges(); TempData["message"] = "Discovery and Rediscovery Data Imported"; } } if (download == "on") { System.IO.MemoryStream stream = new System.IO.MemoryStream(); XmlTextWriter writer = new XmlTextWriter(stream, System.Text.Encoding.UTF8); xml.WriteTo(writer); writer.Flush(); Response.Clear(); byte[] byteArray = stream.ToArray(); Response.AppendHeader("Content-Disposition", "attachment; filename=" + asset.ToString() + ".xml"); Response.AppendHeader("Content-Length", byteArray.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(byteArray); writer.Close(); Response.End(); } } else { TempData["message"] = "an error has occurred"; } return(View()); }
public ActionResult csv(HttpPostedFileBase FileUpload, string station) { string path = ""; DataTable dt = new DataTable(); //check we have a file if (FileUpload.ContentLength > 0) { //Workout our file path string fileName = Path.GetFileName(FileUpload.FileName); path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); //Try and upload try { FileUpload.SaveAs(path); //Process the CSV file and capture the results to our DataTable holder List <string> temp_line = new List <string>(); using (StringReader reader = new StringReader(System.IO.File.ReadAllText(path))) { string line = null; while ((line = reader.ReadLine()) != null) { if (!temp_line.Contains(line)) { temp_line.Add(line); } } } string check = temp_line[2].ToString(); if (check.Contains("Office") && !station.ToString().Contains("ocoa")) { TempData["message"] = "Error ---CSV might not match COA type----"; return(RedirectToAction("admin", "Manage")); } else if (check.Contains("Windows") && !station.ToString().Contains("wcoa")) { TempData["message"] = "Error ---CSV might not match COA type----"; return(RedirectToAction("admin", "Manage")); } using (StreamWriter writer = new StreamWriter(System.IO.File.Open(path, FileMode.Create))) foreach (string value in temp_line) { writer.WriteLine(value); } dt = ProcessCSV(path); foreach (DataRow r in dt.Rows) { var updateQuery = new coas(); updateQuery.Request_ID = int.Parse(r[0].ToString()); updateQuery.COA_ID = r[1].ToString(); updateQuery.Product_Name = r[2].ToString(); updateQuery.Pre_existing_COA_ID = r[3].ToString(); updateQuery.License_Type = r[4].ToString(); updateQuery.PK = r[5].ToString(); updateQuery.PDF_language = r[6].ToString(); updateQuery.Recipient_Organization_Name = r[7].ToString(); updateQuery.Recipient_City = r[8].ToString(); updateQuery.Recipient_Country___Region = r[9].ToString(); updateQuery.Recipient_Type = r[10].ToString(); updateQuery.location = station.ToString(); db.coas.Add(updateQuery); } db.SaveChanges(); dt.Dispose(); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } catch (Exception ex) { if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } //Catch errors TempData["Feedback"] = ex.ToString(); } } else { //Catch errors TempData["Feedback"] = "Please select a file"; } //Tidy up return(RedirectToAction("admin")); }