/// <summary> /// Deprecated Method for adding a new object to the recsys_costs EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTorecsys_costs(recsys_costs recsys_costs) { base.AddObject("recsys_costs", recsys_costs); }
public JsonResult CostBatchInsertProcess(FormCollection elements) { bool isSuccess = false; Dictionary<int, recsys_costs> insertItems = new Dictionary<int, recsys_costs>(); List<string> validationControlSelectors = new List<string>(); string relateIDString = elements["hfRelateID"]; string relateTableString = elements["hfRelateTable"]; string relateCenter = "68"; //get relateCenter with relateIDString and relateTableString int relateID1 = Convert.ToInt32(relateIDString); if (relateTableString == "quotation") { var records = from q in this._db.recsys_quotation join rc in this._db.recsys_relate_customers on q.customer_id equals rc.id into rcs from rc in rcs.DefaultIfEmpty() where q.id == relateID1 select new { relateCenter = rc.center }; var record = records.FirstOrDefault(); relateCenter = record.relateCenter; } else { var records = from q in this._db.recsys_maintenance join rc in this._db.recsys_relate_customers on q.customer_id equals rc.id into rcs from rc in rcs.DefaultIfEmpty() where q.id == relateID1 select new { relateCenter = rc.center }; var record = records.FirstOrDefault(); relateCenter = record.relateCenter; } int relateID; if (int.TryParse(relateIDString, out relateID)) { string[] isValidRecords = elements.GetValues("hfValid"); string[] supplierSubConIDs = elements.GetValues("hfSupplierSubContractorID"); string[] supplierSubConRoles = elements.GetValues("hfSupplierSubContractorRole"); string[] workerIDs = elements.GetValues("hfWorkerID"); //string[] centerNames = elements.GetValues("cbCenter"); string[] categoryIDs = elements.GetValues("hfCategoryID"); string[] invoiceDates = elements.GetValues("tbBillingDate"); string[] prices = elements.GetValues("tbPrice"); string[] invoiceNumbers = elements.GetValues("tbInvoice"); string[] remarks = elements.GetValues("tbRemark"); int itemsCount = isValidRecords.Count(); for (int i = 0; i < itemsCount; i++) { recsys_costs cost = new recsys_costs() { account_date = null, center = "", cost_id = null, invoice = "", last_update = DateTime.Now, remark = "", status = 0, supplier_id = null, update_user_id = 0, user_id = null, price1 = null, price2 = null }; //DateTime invoiceDate; int categoryID; double price; int supplierID; int subConID; int workerID; bool isValid; Member member = new Member("users"); if (!string.IsNullOrEmpty(invoiceDates[i])) cost.account_date = DateTime.ParseExact(invoiceDates[i], "dd-MM-yyyy", null); /*if (DateTime.TryParse(invoiceDates[i], out invoiceDate)) cost.account_date = invoiceDate;*/ cost.center = relateCenter; if (int.TryParse(categoryIDs[i], out categoryID)) cost.cost_id = categoryID; cost.invoice = invoiceNumbers[i]; if (double.TryParse(prices[i], out price)) cost.price1 = price; cost.remark = remarks[i]; if (bool.TryParse(isValidRecords[i], out isValid)) { if (isValid) cost.status = (int)RecordStatus.Active; else cost.status = (int)RecordStatus.InActive; } if (supplierSubConRoles[i] == ((int)SupplierSubConType.Supplier).ToString()) { if (int.TryParse(supplierSubConIDs[i], out supplierID)) cost.supplier_id = supplierID; } else if (supplierSubConRoles[i] == ((int)SupplierSubConType.SubContractor).ToString()) { if (int.TryParse(supplierSubConIDs[i], out subConID)) cost.user_id = subConID; } if (int.TryParse(workerIDs[i], out workerID)) cost.user_id = workerID; cost.update_user_id = (int)member.infoBySession("id"); if (cost.user_id > 0 || cost.supplier_id > 0 || cost.cost_id > 0) insertItems.Add(i, cost); } //# Validation foreach (KeyValuePair<int, recsys_costs> kvp in insertItems) { if (!kvp.Value.cost_id.HasValue) validationControlSelectors.Add("#cost_custom_insert_form .tbCategory:eq(" + kvp.Key + ")"); } if (validationControlSelectors.Count > 0) { return Json(new { bIsSuccess = false, exception = new ValidationException("無效的Category", validationControlSelectors.ToArray()) }); } if (insertItems.Count > 0) { List<recsys_costs> items = new List<recsys_costs>(); foreach (KeyValuePair<int, recsys_costs> kvp in insertItems) { items.Add(kvp.Value); this._db.recsys_costs.AddObject(kvp.Value); } try { int number = this._db.SaveChanges(); this._db.Refresh(RefreshMode.StoreWins, items); foreach (recsys_costs item in items) { recsys_relate relation = new recsys_relate(); relation.table1 = "costs"; relation.table2 = relateTableString; relation.id1 = item.id; relation.id2 = relateID; this._db.recsys_relate.AddObject(relation); } this._db.SaveChanges(); isSuccess = true; } catch (OptimisticConcurrencyException) { //# log down } } } return Json(new { bIsSuccess = isSuccess }); }
/// <summary> /// Create a new recsys_costs object. /// </summary> /// <param name="id">Initial value of the id property.</param> /// <param name="status">Initial value of the status property.</param> public static recsys_costs Createrecsys_costs(global::System.Int32 id, global::System.Byte status) { recsys_costs recsys_costs = new recsys_costs(); recsys_costs.id = id; recsys_costs.status = status; return recsys_costs; }