public ActionResult Edit() { Validator _val = new Validator(); string customer_id = Common.doPost("customer_id"); string id = Common.doPost("id"); string content = Common.doPost("content"); string oper = Common.doPost("oper"); string sql; if (oper != "del") { if (oper == "edit") { _val.val(id, new String[] { "req", "int" }); } _val.val(content, "req"); if (_val.val(customer_id, new String[] { "req", "int" })) { int cid = Convert.ToInt32(customer_id); int customers_exist = (from c in this._db.recsys_customers where c.id == cid select c).Count(); if (customers_exist == 0) { _val.setValStatus(false); } } if (_val.getValStatus()) { Member _member = new Member("users"); Hashtable data = new Hashtable() { { "content", content }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") } }; if (oper == "edit") { sql = Common.doUpdate(data, "log", "id = '" + id + "'"); } else { data["customer_id"] = customer_id; data["create_date"] = DateTime.Now.ToString("s"); sql = Common.doInsert(data, "log"); } } else { return Content(Common.json_encode(false)); } } else { sql = Common.doDelete("log", "id = '" + id + "'"); } this._db.ExecuteStoreCommand(sql); return Content(Common.json_encode(true)); }
public static recsys_quotation_package_items CopyQuotationPackageItem(recsys_quotation_package_items target) { recsys_quotation_package_items result = new recsys_quotation_package_items(); Member _member = new Member("users"); if (target != null) { result.code = target.code; result.detail_chi = target.detail_chi; result.detail_eng = target.detail_eng; result.id = 0; result.update_date = System.DateTime.Now; result.nSequence = target.nSequence; result.price = target.price; result.update_by = (int)_member.infoBySession("id"); result.create_date = System.DateTime.Now; result.create_by = (int)_member.infoBySession("id"); result.status = 1; } return result; }
public ActionResult Edit() { Validator _val = new Validator(); string id = Common.doPost("id"); string name = Common.doPost("name"); string status = Common.doPost("status2"); string oper = Common.doPost("oper"); string sql; if(oper != "del") { if(oper == "edit") { _val.val(id, new String[] { "req", "int" }); } _val.val(name, "req"); _val.val(status, new String[] { "req", "int", "get=0", "let=1" }); if(_val.getValStatus()) { Member _member = new Member("users"); Hashtable data = new Hashtable() { { "name", name }, { "status", status }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") } }; if(oper == "edit") { sql = Common.doUpdate(data, "supplier", "id = '" + id + "'"); } else { sql = Common.doInsert(data, "supplier"); } } else { return Content(Common.json_encode(false)); } } else { sql = Common.doDelete("supplier", "id = '" + id + "'"); } this._db.ExecuteStoreCommand(sql); return Content(Common.json_encode(true)); }
public ActionResult Add(recsys_cost data, int status2) { bool isSuccess = false; Member member = new Member("users"); data.last_update = DateTime.Now; data.update_user_id = (int)member.infoBySession("id"); data.status = (byte)(((RecordStatus)status2) == RecordStatus.Active ? 1 : 0); this._db.recsys_cost.AddObject(data); try { this._db.SaveChanges(); isSuccess = true; } catch (OptimisticConcurrencyException) { //# log down } return Json(isSuccess, JsonRequestBehavior.AllowGet); }
public ActionResult Index() { Member member = new Member("users"); OrderIndexViewModel model = new OrderIndexViewModel() { UserType = (UserType)int.Parse(member.infoBySession("type").ToString()), RepaireDateOnORBefore = null, ShowContractOrder = false, ShowECall = true, OrderStatus = 0, OrderStatuses = this._orderECallStatuses }; return View(model); }
public ActionResult EditSave(QuotationRecord data) { recsys_quotation quotation; recsys_relate_customers customerData; //# validation if (data.id < 0) throw new SystemException("Invalid Entity ID"); if (!String.IsNullOrEmpty(data.invoice) && data.dummy) { data.SaveResult.WarningMessage = "請刪除Invoice No或取消選取'有Dummy Invoice'"; data.SaveResult.SavedSuccessfully = false; return Json(data); } if (!String.IsNullOrEmpty(data.minor_work)) { if (data.minor_work.Length > 3) { data.SaveResult.WarningMessage = "請修改Minor Work至3字以內"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } //# get old record var records = from q in this._db.recsys_quotation join c in this._db.recsys_relate_customers on q.customer_id equals c.id into cs from c in cs.DefaultIfEmpty() where q.id == data.id select new { Quotation = q, CustomerData = c }; var record = records.FirstOrDefault(); Member member = new Member("users"); //# validation if (record == null) throw new RecordNotFoundException(); quotation = record.Quotation; customerData = record.CustomerData; //# validation if (quotation == null || customerData == null) throw new RecordNotFoundException(); if (!quotation.last_update.HasValue) throw new ImproperDataException(); if (quotation.last_update.Value > data.FetchRecordTime) throw new OptimisticConcurrencyException("資料已被其他使用者更新"); bool createNewDistrict = false; if (!string.IsNullOrEmpty(data.WorkingDistrictName)) { recsys_district workingDistrict = this._db.recsys_district.Where(x => x.name.Trim().ToUpper().Equals(data.WorkingDistrictName.Trim().ToUpper())).SingleOrDefault(); if (workingDistrict != null) { data.district2 = workingDistrict.id; data.group_id = workingDistrict.group_id; } else createNewDistrict = true; } if (createNewDistrict) { recsys_district addNewDistrict = new recsys_district() { code = data.WorkingDistrictName.Trim(), name = data.WorkingDistrictName.Trim(), group_id = this._db.recsys_group.Where(x => x.name.Equals("Unknown Group For System Migration")).SingleOrDefault().id, region = 4, status = 1, last_update = DateTime.Now, update_user_id = (int)member.infoBySession("id") }; this._db.recsys_district.AddObject(addNewDistrict); this._db.SaveChanges(); data.district2 = this._db.recsys_district.Where(x => x.name.Equals(data.WorkingDistrictName.Trim())).SingleOrDefault().id; data.group_id = this._db.recsys_district.Where(x => x.name.Equals(data.WorkingDistrictName.Trim())).SingleOrDefault().group_id; } createNewDistrict = false; if (!string.IsNullOrEmpty(data.MailingDistrictName)) { recsys_district mailingDistrict = this._db.recsys_district.Where(x => x.name.Trim().ToUpper().Equals(data.MailingDistrictName.Trim().ToUpper())).SingleOrDefault(); if (mailingDistrict != null) { data.district1 = mailingDistrict.id; data.group_id = mailingDistrict.group_id; } else createNewDistrict = true; } if (createNewDistrict) { recsys_district addNewDistrict = new recsys_district() { code = data.MailingDistrictName.Trim(), name = data.MailingDistrictName.Trim(), group_id = this._db.recsys_group.Where(x => x.name.Equals("Unknown Group For System Migration")).SingleOrDefault().id, region = 4, status = 1, last_update = DateTime.Now, update_user_id = (int)member.infoBySession("id") }; this._db.recsys_district.AddObject(addNewDistrict); this._db.SaveChanges(); data.district1 = this._db.recsys_district.Where(x => x.name.Equals(data.MailingDistrictName.Trim())).SingleOrDefault().id; data.group_id = this._db.recsys_district.Where(x => x.name.Equals(data.MailingDistrictName.Trim())).SingleOrDefault().group_id; } //# saving //# mapping quotation.billing_date = DateChecking(data.billing_date); quotation.confirm_date = DateChecking(data.confirm_date); quotation.dummy = (byte)(data.dummy ? 1 : 0); quotation.dummy_date = DateChecking(data.dummy_date); quotation.initial = data.initial; quotation.invoice = data.invoice; quotation.invoice_date = DateChecking(data.billing_date); quotation.minor_work = data.minor_work; quotation.minor_work_currency = data.minor_work_currency.HasValue ? data.minor_work_currency : 0.00; quotation.gp = data.gp.HasValue ? data.gp : 0.0; quotation.lang = data.lang; quotation.last_update = DateTime.Now; quotation.order_number = data.order_number; quotation.number = data.number; quotation.remark = data.remark2; quotation.status = (byte)data.status; quotation.subcon_estimation = data.subcon_estimation.HasValue ? data.subcon_estimation : 0.00; quotation.subcon_name = data.subcon_name; quotation.subcon_estimation2 = data.subcon_estimation2.HasValue ? data.subcon_estimation2 : 0.00; quotation.subcon_name2 = data.subcon_name2; quotation.subcon_estimation3 = data.subcon_estimation3.HasValue ? data.subcon_estimation3 : 0.00; quotation.subcon_name3 = data.subcon_name3; quotation.supplier_name = data.supplier_name; quotation.supplier_name2 = data.supplier_name2; quotation.supplier_name3 = data.supplier_name3; quotation.supplier_estimation = data.supplier_estimation.HasValue ? data.supplier_estimation : 0.00; quotation.supplier_estimation2 = data.supplier_estimation2.HasValue ? data.supplier_estimation2 : 0.00; quotation.supplier_estimation3 = data.supplier_estimation3.HasValue ? data.supplier_estimation3 : 0.00; quotation.supervision = data.supervision.HasValue ? data.supervision : 0.00; quotation.supplier_id = data.supplier_id.HasValue ? data.supplier_id : 0.00; quotation.material_estimation2 = data.material_estimation2.HasValue ? data.material_estimation2 : 0.00; quotation.material_estimation3 = data.material_estimation3.HasValue ? data.material_estimation3 : 0.00; quotation.direct_labour = data.direct_labour; quotation.direct_labour_cost = data.direct_labour_cost.HasValue ? data.direct_labour_cost : 0.00; quotation.payment_received_date = DateChecking(data.payment_received_date); quotation.tender_number = data.tender_number; quotation.update_user_id = (int)member.infoBySession("id"); quotation.issue_date = DateChecking(data.issue_date); customerData.address1 = data.address1; customerData.address2 = data.address2; customerData.contact = data.contact; customerData.district1 = data.district1; customerData.district2 = data.district2; customerData.email = data.email; customerData.fax1 = data.fax1; customerData.fax2 = data.fax2; customerData.group_id = data.group_id; customerData.name = data.name; customerData.chi_name = data.chi_name; customerData.remark = data.remark; customerData.tel1 = data.tel1; customerData.tel2 = data.tel2; customerData.title = (byte)data.title; try { this._db.SaveChanges(); this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, quotation); data.id = quotation.id; data.SaveResult.SavedSuccessfully = true; } catch (OptimisticConcurrencyException) { //# log down } return Json(data); }
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 }); }
public ActionResult Parts_Edit() { Validator _val = new Validator(); string id = Common.doPost("id"); string order_id = Common.doPost("order_id"); string supplier_id = Common.doPost("supplier_id"); string name = Common.doPost("name"); string invoice = Common.doPost("invoice"); string price1 = Common.doPost("price1"); string price2 = Common.doPost("price2"); string detail = Common.doPost("detail"); string account_date = Common.doPost("account_date2"); string remark = Common.doPost("remark"); string status = Common.doPost("status2"); string oper = Common.doPost("oper"); string sql; if(oper != "del") { if(oper == "edit") { _val.val(id, new String[] { "req", "int" }); } _val.val(order_id, new String[] { "req", "int" }); _val.val(name, "req"); _val.val(status, new String[] { "req", "int", "get=0", "let=1" }); if(_val.getValStatus()) { Member _member = new Member("users"); Hashtable data = new Hashtable() { { "supplier_id", supplier_id }, { "name", name }, { "invoice", invoice }, { "price1", price1 }, { "price2", price2 }, { "detail", detail }, { "account_date", account_date }, { "remark", remark }, { "status", status }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") } }; if(oper == "edit") { sql = Common.doUpdate(data, "parts", "id = '" + id + "'"); } else { sql = Common.doInsert(data, "parts"); this._db.ExecuteStoreCommand(sql); id = (from p in this._db.recsys_parts orderby p.id descending select p.id).FirstOrDefault().ToString(); data = new Hashtable() { { "id1", id }, { "id2", order_id }, { "table1", "parts" }, { "table2", "order" } }; sql = Common.doInsert(data, "relate"); } } else { return Content(Common.json_encode(false)); } } else { sql = Common.doDelete("relate", "id1 = '" + id + "' AND table1 = 'parts'"); this._db.ExecuteStoreCommand(sql); sql = Common.doDelete("parts", "id = '" + id + "'"); } this._db.ExecuteStoreCommand(sql); return Content(Common.json_encode(true)); }
public ActionResult DuplicateQuotation(int? id, int customerID) { //# validation if (!id.HasValue) return Json(new { bIsSuccessful = false }); bool isSuccessful = false; Member member = new Member("users"); int newQuotationID = 0; string customerCode = ""; try { //# get existing quotation recsys_quotation existingQuotation = this._db.recsys_quotation.FirstOrDefault(theQuotation => theQuotation.id == id.Value); if (existingQuotation != null) { //# get customer data for the newly duplicated quotation recsys_customers existingQuotationCustomerData = this._db.recsys_customers.FirstOrDefault(theCustomerData => theCustomerData.id == customerID); if (existingQuotationCustomerData != null) { //# get existing quotation items IEnumerable<recsys_quotation_items> existingQuotationItems = from r in this._db.recsys_relate join qi in this._db.recsys_quotation_items on r.id2 equals qi.id where r.id1 == id.Value && r.table1 == "quotation" && r.table2 == "quotation_items" select qi; //# construct new customer data recsys_relate_customers newQuotationCustomerData = new recsys_relate_customers { address1 = existingQuotationCustomerData.address1, address2 = existingQuotationCustomerData.address2, center = existingQuotationCustomerData.center, code = existingQuotationCustomerData.code, contact = existingQuotationCustomerData.contact, customer_code = existingQuotationCustomerData.customer_code, customer_id = existingQuotationCustomerData.id, district1 = existingQuotationCustomerData.district1, district2 = existingQuotationCustomerData.district2, email = existingQuotationCustomerData.email, fax1 = existingQuotationCustomerData.fax1, fax2 = existingQuotationCustomerData.fax2, group_id = existingQuotationCustomerData.group_id, name = existingQuotationCustomerData.name, chi_name = existingQuotationCustomerData.chi_name, prefix = existingQuotationCustomerData.prefix, relate_type = 3, remark = existingQuotationCustomerData.remark, reference_number = existingQuotationCustomerData.reference_number, tel1 = existingQuotationCustomerData.tel1, tel2 = existingQuotationCustomerData.tel2, title = existingQuotationCustomerData.title, type = existingQuotationCustomerData.type }; customerCode = newQuotationCustomerData.customer_code; //# construct new quotation items recsys_quotation_items[] newQuotationItems = existingQuotationItems.Select(theItem => QuotationsController.CopyQuotationItem(theItem)).ToArray(); this._db.recsys_relate_customers.AddObject(newQuotationCustomerData); foreach (recsys_quotation_items item in newQuotationItems) { item.last_update = DateTime.Now; item.update_user_id = (int)member.infoBySession("id"); this._db.recsys_quotation_items.AddObject(item); } //# save customer data this._db.SaveChanges(); //# load new customer data this._db.Refresh(RefreshMode.StoreWins, newQuotationCustomerData); //# load new items this._db.Refresh(RefreshMode.StoreWins, newQuotationItems); if (newQuotationCustomerData.id > 0) { //# construct new quotation recsys_quotation newQuotation = new recsys_quotation(); newQuotation.create_date = DateTime.Now; newQuotation.customer_id = newQuotationCustomerData.id; newQuotation.last_update = DateTime.Now; newQuotation.update_user_id = (int)member.infoBySession("id"); newQuotation.status = 1; newQuotation.issue_date = DateTime.Now.Date; if (existingQuotation.lang != 0) newQuotation.lang = existingQuotation.lang; else newQuotation.lang = 1; //default chinese this._db.recsys_quotation.AddObject(newQuotation); //# save quotation this._db.SaveChanges(); //# load new quotation this._db.Refresh(RefreshMode.StoreWins, newQuotation); newQuotationID = newQuotation.id; if (newQuotation.id > 0 && newQuotationItems.Count(theItem => theItem.id > 0) > 0) { //# construct relations IEnumerable<recsys_relate> relations = newQuotationItems.Where(theItem => theItem.id > 0) .Select(theItem => new recsys_relate() { id1 = newQuotation.id, id2 = theItem.id, table1 = "quotation", table2 = "quotation_items" }); foreach (recsys_relate relation in relations) this._db.recsys_relate.AddObject(relation); //# save relations this._db.SaveChanges(); isSuccessful = true; } else isSuccessful = true; } } } //# duplicate quotation //# save changes } catch (OptimisticConcurrencyException) { //# log down } return Json(new { bIsSuccessful = true, iNewID = newQuotationID, code = customerCode }); }
public ActionResult AddSave(OrderRecord data) { //# validation if (data.MasterRecordID < 0) throw new SystemException("Invalid Entity ID"); int timeInt = 0; if (!String.IsNullOrEmpty(data.StartTimeHour)) { if (!Int32.TryParse(data.StartTimeHour, out timeInt) || Convert.ToInt32(data.StartTimeHour) < 0 || Convert.ToInt32(data.StartTimeHour) > 23) { data.SaveResult.WarningMessage = "請修改開始時間"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } if (!String.IsNullOrEmpty(data.StartTimeMinute)) { if (!Int32.TryParse(data.StartTimeMinute, out timeInt) || Convert.ToInt32(data.StartTimeMinute) < 0 || Convert.ToInt32(data.StartTimeMinute) > 59) { data.SaveResult.WarningMessage = "請修改開始時間"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } if (!String.IsNullOrEmpty(data.EndTimeHour)) { if (!Int32.TryParse(data.EndTimeHour, out timeInt) || Convert.ToInt32(data.EndTimeHour) < 0 || Convert.ToInt32(data.EndTimeHour) > 23) { data.SaveResult.WarningMessage = "請修改結束時間"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } if (!String.IsNullOrEmpty(data.EndTimeMinute)) { if (!Int32.TryParse(data.EndTimeMinute, out timeInt) || Convert.ToInt32(data.EndTimeMinute) < 0 || Convert.ToInt32(data.EndTimeMinute) > 59) { data.SaveResult.WarningMessage = "請修改結束時間"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } if (!String.IsNullOrEmpty(data.repair_date) && !String.IsNullOrEmpty(data.CompleteDate)) { if (DateTime.ParseExact(data.CompleteDate, "dd-MM-yyyy", null) < DateTime.ParseExact(data.repair_date, "dd-MM-yyyy", null)) { data.SaveResult.WarningMessage = "完成日期應在維修日期之後"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } Member member = new Member("users"); bool createNewDistrict = false; if (!string.IsNullOrEmpty(data.WorkingDistrictName)) { recsys_district workingDistrict = this._db.recsys_district.Where(x => x.name.Trim().ToUpper().Equals(data.WorkingDistrictName.Trim().ToUpper())).SingleOrDefault(); if (workingDistrict != null) { data.district2 = workingDistrict.id; data.group_id = workingDistrict.group_id; } else createNewDistrict = true; } if (createNewDistrict) { recsys_district addNewDistrict = new recsys_district() { code = data.WorkingDistrictName.Trim(), name = data.WorkingDistrictName.Trim(), group_id = this._db.recsys_group.Where(x => x.name.Equals("Unknown Group For System Migration")).SingleOrDefault().id, region = 4, status = 1, last_update = DateTime.Now, update_user_id = (int)member.infoBySession("id") }; this._db.recsys_district.AddObject(addNewDistrict); this._db.SaveChanges(); data.district2 = this._db.recsys_district.Where(x => x.name.Equals(data.WorkingDistrictName.Trim())).SingleOrDefault().id; data.group_id = this._db.recsys_district.Where(x => x.name.Equals(data.WorkingDistrictName.Trim())).SingleOrDefault().group_id; } createNewDistrict = false; if (!string.IsNullOrEmpty(data.MailingDistrictName)) { recsys_district mailingDistrict = this._db.recsys_district.Where(x => x.name.Trim().ToUpper().Equals(data.MailingDistrictName.Trim().ToUpper())).SingleOrDefault(); if (mailingDistrict != null) { data.district1 = mailingDistrict.id; data.group_id = mailingDistrict.group_id; } else createNewDistrict = true; } if (createNewDistrict) { recsys_district addNewDistrict = new recsys_district() { code = data.MailingDistrictName.Trim(), name = data.MailingDistrictName.Trim(), group_id = this._db.recsys_group.Where(x => x.name.Equals("Unknown Group For System Migration")).SingleOrDefault().id, region = 4, status = 1, last_update = DateTime.Now, update_user_id = (int)member.infoBySession("id") }; this._db.recsys_district.AddObject(addNewDistrict); this._db.SaveChanges(); data.district1 = this._db.recsys_district.Where(x => x.name.Equals(data.MailingDistrictName.Trim())).SingleOrDefault().id; data.group_id = this._db.recsys_district.Where(x => x.name.Equals(data.MailingDistrictName.Trim())).SingleOrDefault().group_id; } //# get old master customer record if (data.MasterRecordType == OrderMasterRecordType.quotation) return this.AddSave_Quotation(data); else return this.AddSave_Maintenance(data); }
public ActionResult DetailsAdd(recsys_quotation_packages data) { bool isSuccess = false; int id = 0; Member member = new Member("users"); data.status = 1; data.create_date = DateTime.Now; data.create_by = (int)member.infoBySession("id"); data.update_date = DateTime.Now; data.update_by = (int)member.infoBySession("id"); data.code = data.code.Trim(); if (data.package_name == null) data.package_name = ""; else data.package_name = data.package_name.Trim(); if (data.remark != null) data.remark = data.remark.Trim(); if (data.price == null) data.price = 0.0; var quotationPackages = from qp in this._db.recsys_quotation_packages where qp.status == 1 select qp; foreach (recsys_quotation_packages quotationPackage in quotationPackages) { if (!string.IsNullOrEmpty(data.code) && data.code.Trim().ToUpper() == quotationPackage.code.Trim().ToUpper()) { string message = "已有Quotation Package (" + data.code.Trim().ToUpper() + ")"; return Json( new { isSuccess = isSuccess, message = message }, JsonRequestBehavior.AllowGet); } } this._db.recsys_quotation_packages.AddObject(data); try { this._db.SaveChanges(); id = data.id; isSuccess = true; } catch (OptimisticConcurrencyException) { //# log down } // return Content(Common.json_encode(true)); return Json( new { isSuccess = isSuccess, newid = id }, JsonRequestBehavior.AllowGet); }
public ActionResult Edit_Jobs() { Validator _val = new Validator(); string order_id = Common.doPost("order_id"); string id = Common.doPost("id"); string detail1 = Common.doPost("detail1"); string detail2 = Common.doPost("detail2"); string oper = Common.doPost("oper"); string sql; if (oper != "del") { if (oper == "edit") { _val.val(id, new String[] { "req", "int" }); } else { int order = Convert.ToInt32(order_id); int order_exist = (from o in this._db.recsys_order where o.id == order select o).Count(); if (order_exist == 0) { _val.setValStatus(false); } _val.val(order_id, new String[] { "req", "int" }); } _val.val(detail1, "req"); _val.val(detail2, "req"); if (_val.getValStatus()) { Member _member = new Member("users"); Hashtable data = new Hashtable() { { "detail1", detail1 }, { "detail2", detail2 }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") } }; if (oper == "edit") { sql = Common.doUpdate(data, "job", "id = '" + id + "'"); } else { sql = Common.doInsert(data, "job"); this._db.ExecuteStoreCommand(sql); id = (from j in this._db.recsys_job orderby j.id descending select j.id).FirstOrDefault().ToString(); data = new Hashtable() { { "id1", order_id }, { "id2", id }, { "table1", "order" }, { "table2", "job" } }; sql = Common.doInsert(data, "relate"); } } else { return Content(Common.json_encode(false)); } } else { sql = Common.doDelete("relate", "id2 = '" + id + "' AND table2 = 'job'"); this._db.ExecuteStoreCommand(sql); sql = Common.doDelete("job", "id = '" + id + "'"); } this._db.ExecuteStoreCommand(sql); return Content(Common.json_encode(true)); }
public ActionResult Index() { Member _member = new Member("users"); ViewBag.title = this._title; ViewBag.status = this._status; ViewBag.type = _member.infoBySession("type"); return View(); }
public ActionResult Edit2(string id) { Validator _val = new Validator(); string engineer_id_1 = Common.doPost("engineer_id_1"); string engineer_id_2 = Common.doPost("engineer_id_2"); Member _member = new Member("users"); Hashtable data = new Hashtable() { { "engineer_id_1", engineer_id_1 }, { "engineer_id_2", engineer_id_2 }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") }, }; string sql = Common.doUpdate(data, "order", "id = '" + id + "'"); this._db.ExecuteStoreCommand(sql); return Content(Common.json_encode(true)); }
public ActionResult Edit_Extra_Cost() { Validator _val = new Validator(); string order_id = Common.doPost("order_id"); string id = Common.doPost("id"); string name = Common.doPost("name"); string price = Common.doPost("price"); string remark = Common.doPost("remark"); string oper = Common.doPost("oper"); string sql; if (oper != "del") { if (oper == "edit") { _val.val(id, new String[] { "req", "int" }); } else { int order = Convert.ToInt32(order_id); int order_exist = (from o in this._db.recsys_order where o.id == order select o).Count(); if (order_exist == 0) { _val.setValStatus(false); } _val.val(order_id, new String[] { "req", "int" }); } _val.val(name, "req"); _val.val(price, new String[] { "req", "numdec" }); if (_val.getValStatus()) { Member _member = new Member("users"); Hashtable data = new Hashtable() { { "name", name }, { "price", price }, { "remark", remark }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") } }; if (oper == "edit") { sql = Common.doUpdate(data, "extra_cost", "id = '" + id + "'"); } else { data["create_date"] = DateTime.Now.ToString("s"); sql = Common.doInsert(data, "extra_cost"); this._db.ExecuteStoreCommand(sql); id = (from ec in this._db.recsys_extra_cost orderby ec.id descending select ec.id).FirstOrDefault().ToString(); data = new Hashtable() { { "id1", order_id }, { "id2", id }, { "table1", "order" }, { "table2", "extra_cost" } }; sql = Common.doInsert(data, "relate"); } } else { return Content(Common.json_encode(false)); } } else { sql = Common.doDelete("relate", "id2 = '" + id + "' AND table2 = 'extra_cost'"); this._db.ExecuteStoreCommand(sql); sql = Common.doDelete("extra_cost", "id = '" + id + "'"); } this._db.ExecuteStoreCommand(sql); return Content(Common.json_encode(true)); }
public ActionResult Edit(string id, DateTime? completion_date, int? enquery_id, TimeSpan? end_time, int? engineer_id_1, int? engineer_id_2, string fault, string model, string remark2, string repair, DateTime? repair_date, string report, string reviewer, TimeSpan? start_time, byte? status, byte? tc, int? relate_id, string relate_table) { Validator _val = new Validator(); string customer_code = Common.doPost("customer_code"); string mode = Common.doGet("mode"); string type = Common.doPost("type"); string prefix = Common.doPost("prefix"); string code = Common.doPost("code"); string name = Common.doPost("name"); string address1 = Common.doPost("address1"); string address2 = Common.doPost("address2"); string district1 = Common.doPost("district1"); string district2 = Common.doPost("district2"); string title = Common.doPost("title"); string contact = Common.doPost("contact"); string tel1 = Common.doPost("tel1"); string tel2 = Common.doPost("tel2"); string fax1 = Common.doPost("fax1"); string fax2 = Common.doPost("fax2"); string email = Common.doPost("email"); string remark = Common.doPost("remark"); //string model = Common.doPost("model"); //string fault = Common.doPost("fault"); //string repair = Common.doPost("repair"); //dynamic tc = Common.doPost("tc"); //string report = Common.doPost("report"); //string repair_date = Common.doPost("repair_date"); //string start_time = Common.doPost("start_time"); //string end_time = Common.doPost("end_time"); //string remark2 = Common.doPost("remark2"); //string status = Common.doPost("status"); string group_id = Common.doPost("group_id"); string last_update = Common.doPost("last_update"); string oper = Common.doPost("oper"); //string relate_id = Common.doPost("relate_id"); //string relate_table = Common.doPost("relate_table"); string sql; if(oper != "del") { if (oper == "edit") { if (_val.val(id, new String[] { "req", "int" })) { int order_id = Convert.ToInt32(id); string time = ((from o in this._db.recsys_order where o.id == order_id select o.last_update).FirstOrDefault()).ToString(); if (! _val.val(last_update, "equal=" + time)) { return Content(Common.alert("資料已被其他使用者更新")); } } } else { if (type == "3") { _val.val(code, new String[] { "req", "int", "minlen=8", "maxlen=8" }); } _val.val(type, new String[] { "req", "int", "get=1", "let=3" }); } //_val.val(status, new String[] { "req", "int", "get=0", "let=1" }); _val.val(status.ToString(), new String[] { "req", "int", "get=0", "let=1" }); if(_val.getValStatus()) { Member _member = new Member("users"); Hashtable data = new Hashtable() { { "type", type }, { "prefix", prefix }, { "code", code }, { "group_id", group_id }, { "name", name }, { "address1", address1 }, { "address2", address2 }, { "district1", district1 }, { "district2", district2 }, { "title", title }, { "contact", contact }, { "tel1", tel1 }, { "tel2", tel2 }, { "fax1", fax1 }, { "fax2", fax2 }, { "email", email }, { "remark", remark } }; int count = (from c in this._db.recsys_customers where c.customer_code == customer_code select c.id).Count(); if (count == 0) { data["status"] = 1; data["last_update"] = DateTime.Now.ToString("s"); data["update_user_id"] = _member.infoBySession("id"); data["create_date"] = DateTime.Now.ToString("s"); sql = Common.doInsert(data, "customers"); this._db.ExecuteStoreCommand(sql); int cid = (from c in this._db.recsys_customers orderby c.id descending select c.id).FirstOrDefault(); Hashtable data2 = new Hashtable(); if (type != "3") { data2["auto_id"] = Convert.ToInt32((from c in this._db.recsys_customers where c.type != 3 && c.auto_id != 0 orderby c.id descending select c.auto_id).FirstOrDefault()) + 1; code = data2["auto_id"].ToString().PadLeft(8, '0'); } customer_code = this._type[type] + prefix + code; data2["customer_code"] = customer_code; sql = Common.doUpdate(data2, "customers", "id = '" + cid + "'"); this._db.ExecuteStoreCommand(sql); data.Remove("status"); data.Remove("last_update"); data.Remove("update_user_id"); data.Remove("create_date"); } int customer_id; data["customer_code"] = customer_code; customer_id = (from c in this._db.recsys_customers where c.customer_code == customer_code select c.id).FirstOrDefault(); data["customer_id"] = customer_id; if (oper == "edit") { int order_id = Convert.ToInt32(id); customer_id = (from o in this._db.recsys_order where o.id == order_id select o.customer_id).FirstOrDefault(); sql = Common.doUpdate(data, "relate_customers", "id = '" + customer_id + "'"); this._db.ExecuteStoreCommand(sql); } else { data["relate_type"] = 4; sql = Common.doInsert(data, "relate_customers"); this._db.ExecuteStoreCommand(sql); customer_id = (from c in this._db.recsys_relate_customers orderby c.id descending select c.id).FirstOrDefault(); } recsys_order newOrder = new recsys_order() { by_system = 0, completion_date = null, create_date = DateTime.Now, customer_id = customer_id, enquery_id = enquery_id, end_time = end_time, engineer_id_1 = engineer_id_1, engineer_id_2 = engineer_id_2, fault = fault, last_update = DateTime.Now, model = model, remark = remark2, repair = repair, repair_date = repair_date, report = report, reviewer = reviewer, start_time = start_time, status = status ?? 1, tc = tc, update_user_id = (int) _member.infoBySession("id") }; if(oper == "edit") { //// //sql = Common.doUpdate(data3, "order", "id = '" + id + "'"); this._db.ExecuteStoreCommand(sql); } else { try { this._db.recsys_order.AddObject(newOrder); this._db.SaveChanges(); this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, newOrder); if (newOrder.id > 0 && relate_id > 0) { id = newOrder.id.ToString(); //# temp solution recsys_relate newRelation = new recsys_relate() { id1 = relate_id.Value, id2 = newOrder.id, table1 = relate_table, table2 = "order" }; this._db.recsys_relate.AddObject(newRelation); this._db.SaveChanges(); this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, newRelation); } //data3["customer_id"] = customer_id; //data3["create_date"] = DateTime.Now.ToString("s"); //sql = Common.doInsert(data3, "order"); //this._db.ExecuteStoreCommand(sql); //id = (from o in this._db.recsys_order // orderby o.id descending // select o.id).FirstOrDefault().ToString(); //if (!String.IsNullOrWhiteSpace(relate_id)) //{ // Hashtable data4 = new Hashtable() //{ // { "id1", relate_id }, // { "id2", id }, // { "table1", relate_table }, // { "table2", "order" } //}; // sql = Common.doInsert(data4, "relate"); // this._db.ExecuteStoreCommand(sql); //} } catch(OptimisticConcurrencyException) { //# log down } } return RedirectToAction("edit", new { id = id, mode = mode, customer_id = customer_id, relate_id = relate_id, relate_table = relate_table }); } else { return Content(Common.alert("輸入錯誤")); } } else { int order_id = Convert.ToInt32(id); int customer_id = (from o in this._db.recsys_order where o.id == order_id select o.customer_id).FirstOrDefault(); sql = Common.doDelete("relate_customers", "id = '" + customer_id + "'"); this._db.ExecuteStoreCommand(sql); int[] parts_id = (from r in this._db.recsys_relate where r.id2 == order_id && r.table1 == "parts" && r.table2 == "order" select r.id1).ToArray(); if (parts_id.Length > 0) { sql = Common.doDelete("parts", "id IN ('" + String.Join("','", parts_id) + "')"); this._db.ExecuteStoreCommand(sql); } int[] job_id = (from r in this._db.recsys_relate where r.id1 == order_id && r.table1 == "order" && r.table2 == "job" select r.id2).ToArray(); if (job_id.Length > 0) { sql = Common.doDelete("job", "id IN ('" + String.Join("','", job_id) + "')"); this._db.ExecuteStoreCommand(sql); } int[] extra_cost_id = (from r in this._db.recsys_relate where r.id1 == order_id && r.table1 == "order" && r.table2 == "extra_cost" select r.id2).ToArray(); if (extra_cost_id.Length > 0) { sql = Common.doDelete("extra_cost", "id IN ('" + String.Join("','", extra_cost_id) + "')"); this._db.ExecuteStoreCommand(sql); } sql = Common.doDelete("relate", "(id1 = '" + id + "' AND table1 = 'order') OR (id2 = '" + id + "' AND table2 = 'order')"); this._db.ExecuteStoreCommand(sql); sql = Common.doDelete("order_report", "order_id = '" + id + "'"); this._db.ExecuteStoreCommand(sql); sql = Common.doDelete("order", "id = '" + id + "'"); this._db.ExecuteStoreCommand(sql); return Content(Common.json_encode(true)); } }
//public ActionResult Table(string id = "") public ActionResult Table(int? relate_id, string relate_table, int? enquery_id, int page, //# jqGrid parameter int rows, //# jqGrid parameter bool _search, //# jqGrid parameter string filters, //# jqGrid parameter string sidx, //# jqGrid parameter string sord, //# jqGrid parameter string id = "") { Member _member = new Member("users"); //string customer_id = Common.doPost("customer_id"); //string relate_id = Common.doPost("relate_id"); //string relate_table = Common.doPost("relate_table"); //string ecall_id = Common.doPost("ecall_id"); //string by_system = Common.doPost("by_system"); string by_system = "1"; //# logic: 1 means by system; Order are all by system //int cid = !String.IsNullOrWhiteSpace(customer_id) ? Convert.ToInt32(customer_id) : 0; //int cid = customer_id.HasValue ? customer_id.Value : 0; //int rid = !String.IsNullOrWhiteSpace(relate_id) ? Convert.ToInt32(relate_id) : 0; int rid = relate_id.HasValue ? relate_id.Value : 0; //int eid = !String.IsNullOrWhiteSpace(ecall_id) ? Convert.ToInt32(ecall_id) : 0; int eid = enquery_id.HasValue ? enquery_id.Value : 0; string where = String.Empty; string sql; if (_member.infoBySession("type").ToString() != "1" && _member.infoBySession("type").ToString() != "5") { int member_id = Convert.ToInt32(_member.infoBySession("id")); int[] group_id = (from g in this._db.recsys_group where g.supervisor_id == member_id select g.id).ToArray(); where = " AND (o.engineer_id_1 = '" + member_id + "' OR o.engineer_id_2 = '" + member_id + "'"; if (group_id.Count() > 0) { where += " OR c.group_id IN ('" + String.Join("','", group_id) + "')"; } where += ")"; } //if (cid > 0) //{ // where += " AND c.customer_id = '" + cid + "'"; //} if (eid > 0) { where += " AND o.enquery_id = '" + eid + "'"; } if (!String.IsNullOrEmpty(by_system)) { where += " AND o.by_system = '" + by_system + "'"; } if (!String.IsNullOrWhiteSpace(id)) { string last_update; if (rid > 0) { sql = Common.doSql("SELECT o.last_update FROM {p}_order AS o LEFT JOIN {p}_relate_customers AS c ON o.customer_id = c.id LEFT JOIN {p}_relate AS r ON o.id = r.id2 WHERE r.id1 = '" + rid + "' AND r.table1 = '" + relate_table + "' AND r.table2 = 'order'" + where + " ORDER BY o.last_update DESC"); } else { sql = Common.doSql("SELECT o.last_update FROM {p}_order AS o LEFT JOIN {p}_relate_customers AS c ON o.customer_id = c.id WHERE 1 = 1" + where + " ORDER BY o.last_update DESC"); } last_update = this._db.ExecuteStoreQuery<DateTime>(sql).FirstOrDefault().ToString(); return Content(String.IsNullOrWhiteSpace(last_update) ? "null" : last_update); } else { Result result; int totalRecordCount; int currentPage; int pageSize; double totalPages; string sortBy = sidx; //# get from jqGrid parameter string sortDirection = sord; //# get from jqGrid parameter Rec_System.Functions.JqGrid.Filter filterList = Rec_System.Functions.JqGrid.Filter.ConvertFromJqGridFilterString(filters); //if (rid > 0) //{ // //sql = Common.doSql(_grid.sql("", "SELECT o.id, o.ecall_id, o.engineer_id_1, o.engineer_id_2, o.remark, o.status, o.repair_date, o.start_time, o.end_time, o.create_date, o.last_update, o.update_user_id, o.fault, c.customer_code, c.name AS customer_name, c.title, c.contact, c.tel1, c.tel2, c.fax1, c.fax2, c.email, c.address1, c.address2, c.remark AS customer_remark, g.name AS group_name, (SELECT name FROM {p}_users AS u WHERE u.id = o.engineer_id_1) AS engineer_name_1, (SELECT name FROM {p}_users AS u WHERE u.id = o.engineer_id_2) AS engineer_name_2 FROM {p}_order AS o LEFT JOIN {p}_relate_customers AS c ON o.customer_id = c.id LEFT JOIN {p}_group AS g on c.group_id = g.id LEFT JOIN {p}_relate AS r ON o.id = r.id2", "r.id1 = '" + rid + "' AND r.table1 = '" + relate_table + "' AND r.table2 = 'order'" + where)); // sql = Common.doSql(_grid.sql("", "SELECT o.id, o.ecall_id, o.engineer_id_1, o.engineer_id_2, o.remark, o.status, o.repair_date, o.completion_date, o.start_time, o.end_time, o.create_date, o.last_update, o.update_user_id, o.fault, c.customer_code, c.name AS customer_name, c.title, c.contact, c.tel1, c.tel2, c.fax1, c.fax2, c.email, c.address1, c.address2, c.remark AS customer_remark, g.name AS group_name, (SELECT name FROM {p}_users AS u WHERE u.id = o.engineer_id_1) AS engineer_name_1, (SELECT name FROM {p}_users AS u WHERE u.id = o.engineer_id_2) AS engineer_name_2 FROM {p}_order AS o LEFT JOIN {p}_relate_customers AS c ON o.customer_id = c.id LEFT JOIN {p}_group AS g on c.group_id = g.id LEFT JOIN {p}_relate AS r ON o.id = r.id2 where 1=1 ", "r.id1 = '" + rid + "' AND r.table1 = '" + relate_table + "' AND r.table2 = 'order'" + where)); //} //else //{ // //sql = Common.doSql(_grid.sql("", "SELECT o.id, o.ecall_id, o.engineer_id_1, o.engineer_id_2, o.remark, o.status, o.repair_date, o.start_time, o.end_time, o.create_date, o.last_update, o.update_user_id, o.fault, c.customer_code, c.name AS customer_name, c.title, c.contact, c.tel1, c.tel2, c.fax1, c.fax2, c.email, c.address1, c.address2, c.remark AS customer_remark, g.name AS group_name, (SELECT name FROM {p}_users AS u WHERE u.id = o.engineer_id_1) AS engineer_name_1, (SELECT name FROM {p}_users AS u WHERE u.id = o.engineer_id_2) AS engineer_name_2 FROM {p}_order AS o LEFT JOIN {p}_relate_customers AS c ON o.customer_id = c.id LEFT JOIN {p}_group AS g on c.group_id = g.id", "1 = 1" + where)); // sql = Common.doSql(_grid.sql("", "SELECT o.id, o.ecall_id, o.engineer_id_1, o.engineer_id_2, o.remark, o.status, o.repair_date, o.completion_date, o.start_time, o.end_time, o.create_date, o.last_update, o.update_user_id, o.fault, c.customer_code, c.name AS customer_name, c.title, c.contact, c.tel1, c.tel2, c.fax1, c.fax2, c.email, c.address1, c.address2, c.remark AS customer_remark, g.name AS group_name, (SELECT name FROM {p}_users AS u WHERE u.id = o.engineer_id_1) AS engineer_name_1, (SELECT name FROM {p}_users AS u WHERE u.id = o.engineer_id_2) AS engineer_name_2 FROM {p}_order AS o LEFT JOIN {p}_relate_customers AS c ON o.customer_id = c.id LEFT JOIN {p}_group AS g on c.group_id = g.id where 1=1 ", "1 = 1" + where)); //} var entities = from o in this._db.recsys_order join c in this._db.recsys_relate_customers on o.customer_id equals c.id into cs from c in cs.DefaultIfEmpty() join g in this._db.recsys_group on c.group_id equals g.id into gs from g in gs.DefaultIfEmpty() join r in this._db.recsys_relate on o.id equals r.id2 into rs from r in rs.DefaultIfEmpty() join eng1 in this._db.recsys_users on o.engineer_id_1 equals eng1.id into eng1s from eng1 in eng1s.DefaultIfEmpty() join eng2 in this._db.recsys_users on o.engineer_id_2 equals eng2.id into eng2s from eng2 in eng2s.DefaultIfEmpty() where r.table1 == relate_table && r.table2 == "order" && o.by_system == 1 && r.id1 == rid select new OrderIndexRecord() { ID = o.id, CompleteDate = o.completion_date, CreateDate = o.create_date, EndTime = o.end_time, Fault = o.fault, OrderRemark = o.remark, Group = g.name, RepairDate = o.repair_date, StartTime = o.start_time, Status = o.status, Worker1 = eng1.name, Worker2 = eng2.name }; //# handle searching if (filterList != null) entities = entities.SearchBy(filterList); //# handle sorting if (!string.IsNullOrEmpty(sortBy)) entities = entities.OrderBy(sortBy, sortDirection.Trim() == "desc"); //# make JqGrid source result totalRecordCount = entities.Count(); currentPage = page; //# get from jqGrid parameter pageSize = rows; //# get from jqGrid parameter totalPages = Math.Ceiling((double)totalRecordCount / pageSize); result = new Result() { rows = this.ConvertJqGridRecord(entities.Skip((currentPage - 1) * pageSize).Take(pageSize).ToArray()), page = currentPage, records = entities.Count(), total = totalPages }; return Json(result, JsonRequestBehavior.AllowGet); } }
public ActionResult report(string id) { Validator _val = new Validator(); dynamic checklist = Common.doPost("checklist"); string model = Common.doPost("model"); string fault = Common.doPost("fault"); string repair = Common.doPost("repair"); string report = Common.doPost("report"); string repair_date = Common.doPost("repair_date"); string start_time = Common.doPost("start_time"); string end_time = Common.doPost("end_time"); string remark = Common.doPost("remark"); string oper = Common.doPost("oper"); string sql; if (oper == "edit") { _val.val(id, new String[] { "req", "int" }); } if (_val.getValStatus()) { Member _member = new Member("users"); Hashtable data = new Hashtable() { { "checklist", checklist != null && checklist.GetType() == typeof(ArrayList) ? String.Join(",", checklist.ToArray()) : checklist }, { "remark", remark }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") } }; if (oper == "edit") { sql = Common.doUpdate(data, "order_report", "order_id = '" + id + "'"); } else { data["order_id"] = id; sql = Common.doInsert(data, "order_report"); } data = new Hashtable() { { "model", model }, { "fault", fault }, { "repair", repair }, { "report", report }, { "repair_date", repair_date }, { "start_time", start_time }, { "end_time", end_time }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") }, }; sql = Common.doUpdate(data, "order", "id = '" + id + "'"); this._db.ExecuteStoreCommand(sql); } else { return Content(Common.alert("輸入錯誤")); } this._db.ExecuteStoreCommand(sql); return RedirectToAction("report", new { id = id }); }
public ActionResult Table_Technician( int page, //# jqGrid parameter int rows, //# jqGrid parameter bool _search, //# jqGrid parameter string filters, //# jqGrid parameter string sidx, //# jqGrid parameter string sord, //# jqGrid parameter string repairDateOnOrBefore, //# UI filters bool showECall, //# UI filters bool showContractOrder, //# UI filters int? orderStatus, //# UI filters bool check_last_update = false) { Member member = new Member("users"); int technicianID = (int)member.infoBySession("id"); Rec_System.Functions.JqGrid.Filter filterList = Rec_System.Functions.JqGrid.Filter.ConvertFromJqGridFilterString(filters); var entities = from o in this._db.recsys_order join c in this._db.recsys_relate_customers on o.customer_id equals c.id into cs from c in cs.DefaultIfEmpty() join eng1 in this._db.recsys_users on o.engineer_id_1 equals eng1.id into eng1s from eng1 in eng1s.DefaultIfEmpty() join eng2 in this._db.recsys_users on o.engineer_id_2 equals eng2.id into eng2s from eng2 in eng2s.DefaultIfEmpty() join eng3 in this._db.recsys_users on o.engineer_id_3 equals eng3.id into eng3s from eng3 in eng3s.DefaultIfEmpty() join eng4 in this._db.recsys_users on o.engineer_id_4 equals eng4.id into eng4s from eng4 in eng4s.DefaultIfEmpty() join cu in this._db.recsys_users on o.call_pickup_user_id equals cu.id into cus from cu in cus.DefaultIfEmpty() where o.engineer_id_1 == technicianID || o.engineer_id_2 == technicianID || o.engineer_id_3 == technicianID || o.engineer_id_4 == technicianID select new OrderIndexRecord() { ID = o.id, WorkingAddress = c.address2, CallPicker = cu.name, CompleteDate = o.completion_date, CreateDate = o.create_date, EndTime = o.end_time, Fault = o.fault, OrderRemark = o.remark, RepairDate = o.repair_date, StartTime = o.start_time, Status = o.status, Worker1 = eng1.name, Worker2 = eng2.name, Worker3 = eng3.name, Worker4 = eng4.name, BySystem = o.by_system, LastUpdateTime = o.last_update, order_status = o.order_status }; //# handle UI filters if (showECall && !showContractOrder) entities = entities.Where(theRecord => theRecord.BySystem == 0); else if (!showECall && showContractOrder) entities = entities.Where(theRecord => theRecord.BySystem == 1); else if (!showECall && !showContractOrder) entities = entities.Where(theRecord => theRecord.BySystem != 0 && theRecord.BySystem != 1); if (!string.IsNullOrEmpty(repairDateOnOrBefore)) entities = entities.Where(theRecord => theRecord.RepairDate <= DateTime.ParseExact(repairDateOnOrBefore, "dd-MM-yyyy", null)); if (orderStatus.HasValue && orderStatus.Value != 0) entities = entities.Where(theRecord => theRecord.order_status == orderStatus.Value); //# handle searching if (filterList != null) entities = entities.SearchBy(filterList); //# use to check if data has updated if (check_last_update) { DateTime? lastUpdate = entities.Max(theRecord => theRecord.LastUpdateTime); int recordCount = entities.Count(); return Content(Common.md5(lastUpdate.ToString() + recordCount)); } else //# get row results { Result result; int totalRecordCount; int currentPage; int pageSize; double totalPages; string sortBy = sidx; //# get from jqGrid parameter string sortDirection = sord; //# get from jqGrid parameter //# handle sorting if (!string.IsNullOrEmpty(sortBy)) { entities = entities.OrderBy(sortBy, sortDirection.Trim() == "desc"); } //# make JqGrid source result totalRecordCount = entities.Count(); currentPage = page; //# get from jqGrid parameter pageSize = rows; //# get from jqGrid parameter totalPages = Math.Ceiling((double)totalRecordCount / pageSize); result = new Result() { rows = this.ConvertJqGridRecord_Index(entities.Skip((currentPage - 1) * pageSize).Take(pageSize).ToArray()), page = currentPage, records = entities.Count(), total = totalPages }; return Json(result, JsonRequestBehavior.AllowGet); } }
public ActionResult Edit_Items_Template() { Validator _val = new Validator(); string id = Common.doPost("id"); string code = Common.doPost("code"); string detail = Common.doPost("detail"); string detail2 = Common.doPost("detail2"); string price = Common.doPost("price"); string oper = Common.doPost("oper"); string sql; if (oper != "del") { if (oper == "edit") { _val.val(id, new String[] { "req", "int" }); } _val.val(code, "req"); if (_val.getValStatus()) { Member _member = new Member("users"); Hashtable data = new Hashtable() { { "code", code }, { "detail", detail }, { "detail2", detail2 }, { "price", price }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") } }; if (oper == "edit") { sql = Common.doUpdate(data, "quotation_items_template", "id = '" + id + "'"); } else { sql = Common.doInsert(data, "quotation_items_template"); } } else { return Content(Common.json_encode(false)); } } else { sql = Common.doDelete("quotation_items_template", "id = '" + id + "'"); } this._db.ExecuteStoreCommand(sql); return Content(Common.json_encode(true)); }
public ActionResult AddSave_Quotation(OrderRecord data) { Member member; recsys_relate_customers masterCustomerData; recsys_relate_customers customerData; recsys_order order; recsys_relate relation; //# validation if (data.MasterRecordID < 0) throw new SystemException("Invalid Entity ID"); //# get old master customer record var _masterCustomerData = from q in this._db.recsys_quotation join cd in this._db.recsys_relate_customers on q.customer_id equals cd.id into cds from cd in cds.DefaultIfEmpty() where q.id == data.MasterRecordID select new { cd }; masterCustomerData = _masterCustomerData.Select(theRecord => theRecord.cd).FirstOrDefault(); //# validation if (masterCustomerData == null) throw new RecordNotFoundException(); member = new Member("users"); //# mapping customerData = new recsys_relate_customers() { address1 = data.address1, address2 = data.address2, center = masterCustomerData.center, code = masterCustomerData.code, contact = data.contact, customer_code = masterCustomerData.customer_code, customer_id = masterCustomerData.customer_id, district1 = data.district1, district2 = data.district2, email = data.email, fax1 = data.fax1, fax2 = data.fax2, group_id = data.group_id, manual_input_code = masterCustomerData.manual_input_code, name = data.name, chi_name = data.chi_name, prefix = masterCustomerData.prefix, relate_type = (int)Rec_System.Models.Customers.CustomerDataRelateType.Quotation, remark = data.remark, tel1 = data.tel1, tel2 = data.tel2, title = (byte)data.title, type = (byte)masterCustomerData.type }; this._db.recsys_relate_customers.AddObject(customerData); TimeSpan? endTime = null; if (!(String.IsNullOrEmpty(data.EndTimeHour)) && !(String.IsNullOrEmpty(data.EndTimeMinute))) endTime = new TimeSpan(Convert.ToInt32(data.EndTimeHour), Convert.ToInt32(data.EndTimeMinute), 0); TimeSpan? startTime = null; if (!(String.IsNullOrEmpty(data.StartTimeHour)) && !(String.IsNullOrEmpty(data.StartTimeMinute))) startTime = new TimeSpan(Convert.ToInt32(data.StartTimeHour), Convert.ToInt32(data.StartTimeMinute), 0); order = new recsys_order() { by_system = 1, completion_date = DateChecking(data.CompleteDate), end_time = endTime, engineer_id_1 = data.engineer_id_1, engineer_id_2 = data.engineer_id_2, engineer_id_3 = data.engineer_id_3, engineer_id_4 = data.engineer_id_4, fault = data.fault, model = data.model, repair = data.repair, repair_date = DateChecking(data.repair_date), report = data.report, reviewer = data.reviewer, start_time = startTime, tc = (byte)(data.tc ? 1 : 0), create_date = DateTime.Now, last_update = DateTime.Now, remark = data.remark2, status = (byte)data.status, update_user_id = (int)member.infoBySession("id"), job_number = data.JobNumber, order_status = data.order_status }; //alter 故障內容 if (!string.IsNullOrEmpty(order.fault)) { int index1 = order.fault.IndexOf("["); int index2 = order.fault.IndexOf("]"); if (index1 > -1 && index2 > -1) order.fault = order.fault.Substring(index2 + 1); } if (order.completion_date.HasValue) { order.order_status = OrderStatus.WarrantyCompleted.ID; order.fault = "[" + OrderStatus.WarrantyCompleted.Name + "] " + order.fault; } else if (order.order_status == OrderStatus.DoingWarranty.ID) { order.fault = "[" + OrderStatus.DoingWarranty.Name + "] " + order.fault; order.order_status = OrderStatus.DoingWarranty.ID; } else if (order.order_status == OrderStatus.AppointedWarranty.ID) { order.fault = "[" + OrderStatus.AppointedWarranty.Name + "] " + order.fault; order.order_status = OrderStatus.AppointedWarranty.ID; } this._db.recsys_order.AddObject(order); try { this._db.SaveChanges(); this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, customerData); this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, order); order.customer_id = customerData.id; this._db.SaveChanges(); data.id = order.id; relation = new recsys_relate() { id1 = data.MasterRecordID, id2 = order.id, table1 = "quotation", table2 = "order" }; this._db.recsys_relate.AddObject(relation); this._db.SaveChanges(); data.SaveResult.SavedSuccessfully = true; } catch (OptimisticConcurrencyException) { //# log down } return Json(data); }
public ActionResult CloneQuotationPackages(int? id) { //# validation if (!id.HasValue) return Json(new { bIsSuccessful = false }); bool isSuccessful = true; Member member = new Member("users"); int newQuotationPackageID = 0; string newCode = ""; string message = "複製失敗!請重試"; try { //# get existing quotation package recsys_quotation_packages existingQuotationPackage = this._db.recsys_quotation_packages.FirstOrDefault(theQuotationPackage => theQuotationPackage.id == id.Value); if (existingQuotationPackage != null) { //# get existing quotation package items IEnumerable<recsys_quotation_package_items> existingQuotationPackageItems = (from qpi in this._db.recsys_quotation_package_items where qpi.quotation_package_id == id && qpi.status == 1 orderby qpi.nSequence select qpi).ToList(); //# check repeated quotation package code newCode = existingQuotationPackage.code + " (Copy)"; var quotationPackages = from qp in this._db.recsys_quotation_packages where qp.status == 1 select qp; foreach (recsys_quotation_packages quotationPackage in quotationPackages) { if (newCode.Trim().ToUpper() == quotationPackage.code.Trim().ToUpper()) { message = "已有Quotation Package (" + newCode + ")"; return Json( new { bIsSuccessful = false, message = message }); } } //# construct new quotation package recsys_quotation_packages newQuotationPackage = new recsys_quotation_packages(); newQuotationPackage.package_name = existingQuotationPackage.package_name; newQuotationPackage.code = newCode; newQuotationPackage.remark = existingQuotationPackage.remark; newQuotationPackage.price = existingQuotationPackage.price; newQuotationPackage.status = 1; newQuotationPackage.create_date = DateTime.Now; newQuotationPackage.update_date = DateTime.Now; newQuotationPackage.create_by = (int)member.infoBySession("id"); newQuotationPackage.update_by = (int)member.infoBySession("id"); newQuotationPackage.district_id = existingQuotationPackage.district_id; newQuotationPackage.customer_type = existingQuotationPackage.customer_type; this._db.recsys_quotation_packages.AddObject(newQuotationPackage); //# save quotation package this._db.SaveChanges(); //# load new quotation package this._db.Refresh(RefreshMode.StoreWins, newQuotationPackage); newQuotationPackageID = newQuotationPackage.id; //# construct new quotation package items recsys_quotation_package_items[] newQuotationPackageItems = existingQuotationPackageItems.Select(theItem => QuotationPackagesController.CopyQuotationPackageItem(theItem)).ToArray(); foreach (recsys_quotation_package_items item in newQuotationPackageItems) { item.quotation_package_id = newQuotationPackageID; this._db.recsys_quotation_package_items.AddObject(item); } //# save data this._db.SaveChanges(); //# load new items this._db.Refresh(RefreshMode.StoreWins, newQuotationPackageItems); } //# clone quotation package //# save changes } catch (OptimisticConcurrencyException) { //# log down } return Json(new { bIsSuccessful = isSuccessful, newCode = newCode, newQuotationPackageID = newQuotationPackageID, message = message }); }
public ActionResult EditSave(OrderRecord data) { recsys_order order; recsys_relate_customers customerData; //# validation if (data.id < 0) throw new SystemException("Invalid Entity ID"); int timeInt = 0; if (!String.IsNullOrEmpty(data.StartTimeHour)) { if (!Int32.TryParse(data.StartTimeHour, out timeInt) || Convert.ToInt32(data.StartTimeHour) < 0 || Convert.ToInt32(data.StartTimeHour) > 23) { data.SaveResult.WarningMessage = "請修改開始時間"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } if (!String.IsNullOrEmpty(data.StartTimeMinute)) { if (!Int32.TryParse(data.StartTimeMinute, out timeInt) || Convert.ToInt32(data.StartTimeMinute) < 0 || Convert.ToInt32(data.StartTimeMinute) > 59) { data.SaveResult.WarningMessage = "請修改開始時間"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } if (!String.IsNullOrEmpty(data.EndTimeHour)) { if (!Int32.TryParse(data.EndTimeHour, out timeInt) || Convert.ToInt32(data.EndTimeHour) < 0 || Convert.ToInt32(data.EndTimeHour) > 23) { data.SaveResult.WarningMessage = "請修改結束時間"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } if (!String.IsNullOrEmpty(data.EndTimeMinute)) { if (!Int32.TryParse(data.EndTimeMinute, out timeInt) || Convert.ToInt32(data.EndTimeMinute) < 0 || Convert.ToInt32(data.EndTimeMinute) > 59) { data.SaveResult.WarningMessage = "請修改結束時間"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } if (!String.IsNullOrEmpty(data.repair_date) && !String.IsNullOrEmpty(data.CompleteDate)) { if (DateTime.ParseExact(data.CompleteDate, "dd-MM-yyyy", null) < DateTime.ParseExact(data.repair_date, "dd-MM-yyyy", null)) { data.SaveResult.WarningMessage = "完成日期應在維修日期之後"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } //# get old record var records = from e in this._db.recsys_order join c in this._db.recsys_relate_customers on e.customer_id equals c.id into cs from c in cs.DefaultIfEmpty() where e.id == data.id select new { Order = e, CustomerData = c }; var record = records.FirstOrDefault(); Member member = new Member("users"); //# validation if (record == null) throw new RecordNotFoundException(); order = record.Order; customerData = record.CustomerData; //# validation if (order == null || customerData == null) throw new RecordNotFoundException(); if (!order.last_update.HasValue) throw new ImproperDataException(); if (order.last_update.Value > data.FetchRecordTime) throw new OptimisticConcurrencyException("資料已被其他使用者更新"); bool createNewDistrict = false; if (!string.IsNullOrEmpty(data.WorkingDistrictName)) { recsys_district workingDistrict = this._db.recsys_district.Where(x => x.name.Trim().ToUpper().Equals(data.WorkingDistrictName.Trim().ToUpper())).SingleOrDefault(); if (workingDistrict != null) { data.district2 = workingDistrict.id; data.group_id = workingDistrict.group_id; } else createNewDistrict = true; } if (createNewDistrict) { recsys_district addNewDistrict = new recsys_district() { code = data.WorkingDistrictName.Trim(), name = data.WorkingDistrictName.Trim(), group_id = this._db.recsys_group.Where(x => x.name.Equals("Unknown Group For System Migration")).SingleOrDefault().id, region = 4, status = 1, last_update = DateTime.Now, update_user_id = (int)member.infoBySession("id") }; this._db.recsys_district.AddObject(addNewDistrict); this._db.SaveChanges(); data.district2 = this._db.recsys_district.Where(x => x.name.Equals(data.WorkingDistrictName.Trim())).SingleOrDefault().id; data.group_id = this._db.recsys_district.Where(x => x.name.Equals(data.WorkingDistrictName.Trim())).SingleOrDefault().group_id; } createNewDistrict = false; if (!string.IsNullOrEmpty(data.MailingDistrictName)) { recsys_district mailingDistrict = this._db.recsys_district.Where(x => x.name.Trim().ToUpper().Equals(data.MailingDistrictName.Trim().ToUpper())).SingleOrDefault(); if (mailingDistrict != null) { data.district1 = mailingDistrict.id; data.group_id = mailingDistrict.group_id; } else createNewDistrict = true; } if (createNewDistrict) { recsys_district addNewDistrict = new recsys_district() { code = data.MailingDistrictName.Trim(), name = data.MailingDistrictName.Trim(), group_id = this._db.recsys_group.Where(x => x.name.Equals("Unknown Group For System Migration")).SingleOrDefault().id, region = 4, status = 1, last_update = DateTime.Now, update_user_id = (int)member.infoBySession("id") }; this._db.recsys_district.AddObject(addNewDistrict); this._db.SaveChanges(); data.district1 = this._db.recsys_district.Where(x => x.name.Equals(data.MailingDistrictName.Trim())).SingleOrDefault().id; data.group_id = this._db.recsys_district.Where(x => x.name.Equals(data.MailingDistrictName.Trim())).SingleOrDefault().group_id; } //# saving //# mapping order.by_system = 1; order.completion_date = DateChecking(data.CompleteDate); if ((String.IsNullOrEmpty(data.EndTimeHour)) && (String.IsNullOrEmpty(data.EndTimeMinute))) order.end_time = null; else order.end_time = new TimeSpan(Convert.ToInt32(data.EndTimeHour), Convert.ToInt32(data.EndTimeMinute), 0); order.engineer_id_1 = data.engineer_id_1; order.engineer_id_2 = data.engineer_id_2; order.engineer_id_3 = data.engineer_id_3; order.engineer_id_4 = data.engineer_id_4; order.fault = data.fault; order.last_update = DateTime.Now; order.model = data.model; order.remark = data.remark2; order.repair = data.repair; order.repair_date = DateChecking(data.repair_date); order.report = data.report; order.reviewer = data.reviewer; if ((String.IsNullOrEmpty(data.StartTimeHour)) && (String.IsNullOrEmpty(data.StartTimeMinute))) order.start_time = null; else order.start_time = new TimeSpan(Convert.ToInt32(data.StartTimeHour), Convert.ToInt32(data.StartTimeMinute), 0); order.status = (byte)data.status; order.tc = (byte)(data.tc ? 1 : 0); order.update_user_id = (int)member.infoBySession("id"); order.job_number = data.JobNumber; order.order_status = data.order_status; customerData.address1 = data.address1; customerData.address2 = data.address2; customerData.contact = data.contact; customerData.district1 = data.district1; customerData.district2 = data.district2; customerData.email = data.email; customerData.fax1 = data.fax1; customerData.fax2 = data.fax2; customerData.group_id = data.group_id; customerData.name = data.name; customerData.chi_name = data.chi_name; customerData.remark = data.remark; customerData.tel1 = data.tel1; customerData.tel2 = data.tel2; customerData.title = (byte)data.title; customerData.reference_number = data.customer_reference_number; //alter 故障內容 if (!string.IsNullOrEmpty(order.fault)) { int index1 = order.fault.IndexOf("["); int index2 = order.fault.IndexOf("]"); if (index1 > -1 && index2 > -1) order.fault = order.fault.Substring(index2 + 1); } if (order.completion_date.HasValue) { order.order_status = OrderStatus.WarrantyCompleted.ID; order.fault = "[" + OrderStatus.WarrantyCompleted.Name + "] " + order.fault; } else if (order.order_status == OrderStatus.DoingWarranty.ID) { order.fault = "[" + OrderStatus.DoingWarranty.Name + "] " + order.fault; order.order_status = OrderStatus.DoingWarranty.ID; } else if (order.order_status == OrderStatus.AppointedWarranty.ID) { order.fault = "[" + OrderStatus.AppointedWarranty.Name + "] " + order.fault; order.order_status = OrderStatus.AppointedWarranty.ID; } try { this._db.SaveChanges(); this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, order); data.id = order.id; data.SaveResult.SavedSuccessfully = true; } catch (OptimisticConcurrencyException) { //# log down } return Json(data); }
public JsonResult CustomEditProcess(FormCollection elements) { bool isSaveSuccess = false; string idString = elements["hfID"]; string isValidRecordString = elements["hfValid"]; string supplierSubConIDString = elements["hfSupplierSubContractorID"]; string supplierSubConRoleString = elements["hfSupplierSubContractorRole"]; string workerIDString = elements["hfWorkerID"]; //string centerNameString = elements["cbCenter"]; string categoryIDString = elements["hfCategoryID"]; string invoiceDateString = elements["tbBillingDate"]; string priceString = elements["tbPrice"]; string invoiceNumberString = elements["tbInvoice"]; string remarkString = elements["tbRemark"]; int id; //# Validation if (string.IsNullOrEmpty(categoryIDString)) { return Json(new { bIsSuccess = false, exception = new ValidationException("無效的Category", "#cost_custom_edit_form .tbCategory") }); } if (int.TryParse(idString, out id)) { recsys_costs cost = this._db.recsys_costs.FirstOrDefault(theCost => theCost.id == id); if (cost != null) { DateTime invoiceDate; int categoryID; double price; int supplierID; int subConID; int workerID; bool isValid; Member member = new Member("users"); //# set to default values: //cost.center = ""; cost.account_date = null; cost.cost_id = null; cost.invoice = ""; cost.price1 = null; cost.remark = ""; cost.supplier_id = null; cost.user_id = null; if (!string.IsNullOrEmpty(invoiceDateString)) cost.account_date = DateTime.ParseExact(invoiceDateString, "dd-MM-yyyy", null); //cost.center = centerNameString; if (int.TryParse(categoryIDString, out categoryID)) cost.cost_id = categoryID; cost.invoice = invoiceNumberString; if (double.TryParse(priceString, out price)) cost.price1 = price; cost.remark = remarkString; if (bool.TryParse(isValidRecordString, out isValid)) { if (isValid) cost.status = (int)RecordStatus.Active; else cost.status = (int)RecordStatus.InActive; } if (supplierSubConRoleString.Equals(SupplierSubConType.Supplier.ToString(), StringComparison.OrdinalIgnoreCase)) { if (int.TryParse(supplierSubConIDString, out supplierID)) cost.supplier_id = supplierID; } else if (supplierSubConRoleString.Equals(SupplierSubConType.SubContractor.ToString(), StringComparison.OrdinalIgnoreCase)) { if (int.TryParse(supplierSubConIDString, out subConID)) cost.user_id = subConID; } if (int.TryParse(workerIDString, out workerID)) cost.user_id = workerID; cost.update_user_id = (int)member.infoBySession("id"); cost.last_update = DateTime.Now; try { int number = this._db.SaveChanges(); string relationSQL = ""; this._db.Refresh(RefreshMode.StoreWins, cost); if (!string.IsNullOrEmpty(relationSQL)) this._db.ExecuteStoreCommand(relationSQL); isSaveSuccess = true; } catch (OptimisticConcurrencyException) { //this._db.Refresh(RefreshMode.ClientWins, items); //this._db.SaveChanges(); //Console.WriteLine("OptimisticConcurrencyException " + "handled and changes saved"); //# log down } } } return Json( new { bIsSuccess = isSaveSuccess }); }
public ActionResult QuickCreateSave(QuotationQuickCreateModel model, List<QuotationQuickCreateQuotationItemModel> items) { bool isSuccess = true; string exceptionMessage = string.Empty; string errorType = string.Empty; Member member = new Member("users"); int quotationID=0; recsys_quotation quotation = null; recsys_relate_customers relateCustomer = null; try { #region Validation if (!model.nCustomerID.HasValue || model.nCustomerID == 0) { return Json(new { isSuccess = false, errorType = "Invalidation", exceptionMessage = "請選擇Customer" }); } if (!model.nWorkingDistrictID.HasValue || model.nWorkingDistrictID == 0) { return Json(new { isSuccess = false, errorType = "Invalidation", exceptionMessage = "請選擇工作地址地區" }); } if (!string.IsNullOrEmpty(model.sInvoiceNumber) && model.bIsDummy) { return Json(new { isSuccess = false, errorType = "Invalidation", exceptionMessage = "請刪除Invoice No或取消選取'Dummy'" }); } if (!string.IsNullOrEmpty(model.sMinorWorkExtension) && model.sMinorWorkExtension.Length > 3) { return Json(new { isSuccess = false, errorType = "Invalidation", exceptionMessage = "請修改Minor Work至3字以內'" }); } if (items != null && items.Count() > 0) { List<string> quotationItemCodes = items.Select(i => i.sCode).ToList(); for (int i = 0; i < quotationItemCodes.Count(); i++) { if (!string.IsNullOrWhiteSpace(quotationItemCodes[i])) { for (int j = i + 1; j < quotationItemCodes.Count(); j++) { if (!string.IsNullOrEmpty(quotationItemCodes[j]) && !string.IsNullOrEmpty(quotationItemCodes[j].Trim()) && quotationItemCodes[j].Trim().ToUpper() == quotationItemCodes[i].Trim().ToUpper()) { return Json(new { isSuccess = false, errorType = "Quotation-Item-Duplication", exceptionMessage = "重覆Quotation item (" + quotationItemCodes[j] + ")", }); } } } } } #endregion Validation if (model.Mode == PageMode.Add) { #region Create Relate Customer recsys_customers rawCustomer = this._db.recsys_customers.Where(c => c.id == model.nCustomerID.Value).FirstOrDefault(); relateCustomer = new recsys_relate_customers() { address1 = rawCustomer.address1, address2 = model.sWorkingAddress, center = rawCustomer.center, code = rawCustomer.code, contact = rawCustomer.contact, customer_code = rawCustomer.customer_code, customer_id = rawCustomer.id, district1 = rawCustomer.district1, district2 = model.nWorkingDistrictID, email = rawCustomer.email, fax1 = rawCustomer.fax1, fax2 = rawCustomer.fax2, group_id = rawCustomer.group_id, manual_input_code = rawCustomer.manual_input_code, name = rawCustomer.name, chi_name = rawCustomer.chi_name, prefix = rawCustomer.prefix, relate_type = (int)Rec_System.Models.Customers.CustomerDataRelateType.Quotation, reference_number = rawCustomer.reference_number, remark = rawCustomer.remark, tel1 = rawCustomer.tel1, tel2 = rawCustomer.tel2, title = rawCustomer.title, type = rawCustomer.type }; this._db.recsys_relate_customers.AddObject(relateCustomer); this._db.SaveChanges(); #endregion Create Relate Customer #region Create Quotation quotation = new recsys_quotation() { customer_id = relateCustomer.id, dummy = (byte)(model.bIsDummy ? 1 : 0), dummy_date = this.ConvertDateStringFormat(model.dDummyDueDate, DATEPICKER_DATE_FORMAT), initial = model.sInitial, lang = 1, order_number = model.sOrderNumber, number = model.sACQNumber, subcon_estimation = model.nSubConEstimation.HasValue ? model.nSubConEstimation : 0.00, subcon_name = model.sSubConName, subcon_estimation2 = model.nSubConEstimation2.HasValue ? model.nSubConEstimation2 : 0.00, subcon_name2 = model.sSubConName2, subcon_estimation3 = model.nSubConEstimation3.HasValue ? model.nSubConEstimation3 : 0.00, subcon_name3 = model.sSubConName3, supervision = model.nSupervision.HasValue ? model.nSupervision : 0.00, supplier_id = model.nMaterialEstimation.HasValue ? model.nMaterialEstimation : 0.00, material_estimation2 = model.nMaterialEstimation2.HasValue ? model.nMaterialEstimation2 : 0.00, material_estimation3 = model.nMaterialEstimation3.HasValue ? model.nMaterialEstimation3 : 0.00, supplier_estimation = model.nSupplierEstimation.HasValue ? model.nSupplierEstimation : 0.00, supplier_name = model.sSupplierName, supplier_estimation2 = model.nSupplierEstimation2.HasValue ? model.nSupplierEstimation2 : 0.00, supplier_name2 = model.sSupplierName2, supplier_estimation3 = model.nSupplierEstimation3.HasValue ? model.nSupplierEstimation3 : 0.00, supplier_name3 = model.sSupplierName3, payment_received_date = this.ConvertDateStringFormat(model.dPaymentRecdDate, DATEPICKER_DATE_FORMAT), tender_number = model.sTenderNumber, direct_labour = model.bIsDirectLabour, direct_labour_cost = model.nDirectLabourCost.HasValue ? model.nDirectLabourCost : 0.00, billing_date = this.ConvertDateStringFormat(model.dBillingDate, DATEPICKER_DATE_FORMAT), confirm_date = this.ConvertDateStringFormat(model.dConfirmDate, DATEPICKER_DATE_FORMAT), create_date = DateTime.Now, invoice = model.sInvoiceNumber, invoice_date = this.ConvertDateStringFormat(model.dInvoiceDate, DATEPICKER_DATE_FORMAT), minor_work = model.sMinorWorkExtension, minor_work_currency = model.nMinorWork.HasValue ? model.nMinorWork : 0.00, gp = model.nGP.HasValue ? model.nGP : 0.00, last_update = DateTime.Now, remark = model.sRemark, status = 1, update_user_id = (int)member.infoBySession("id"), issue_date = this.ConvertDateStringFormat(model.dIssueDate, DATEPICKER_DATE_FORMAT) }; if (model.Mode==PageMode.Add) this._db.recsys_quotation.AddObject(quotation); this._db.SaveChanges(); #endregion Create Update Quotation } else { #region Update Quotation quotation = (from q in this._db.recsys_quotation where q.id == model.nQuotationID select q).FirstOrDefault(); quotation.dummy = (byte)(model.bIsDummy ? 1 : 0); quotation.dummy_date = this.ConvertDateStringFormat(model.dDummyDueDate, DATEPICKER_DATE_FORMAT); quotation.initial = model.sInitial; quotation.order_number = model.sOrderNumber; quotation.number = model.sACQNumber; quotation.subcon_estimation = model.nSubConEstimation.HasValue ? model.nSubConEstimation : 0.00; quotation.subcon_name = model.sSubConName; quotation.subcon_estimation2 = model.nSubConEstimation2.HasValue ? model.nSubConEstimation2 : 0.00; quotation.subcon_name2 = model.sSubConName2; quotation.subcon_estimation3 = model.nSubConEstimation3.HasValue ? model.nSubConEstimation3 : 0.00; quotation.subcon_name3 = model.sSubConName3; quotation.supervision = model.nSupervision.HasValue ? model.nSupervision : 0.00; quotation.supplier_id = model.nMaterialEstimation.HasValue ? model.nMaterialEstimation : 0.00; quotation.material_estimation2 = model.nMaterialEstimation2.HasValue ? model.nMaterialEstimation2 : 0.00; quotation.material_estimation3 = model.nMaterialEstimation3.HasValue ? model.nMaterialEstimation3 : 0.00; quotation.supplier_estimation = model.nSupplierEstimation.HasValue ? model.nSupplierEstimation : 0.00; quotation.supplier_name = model.sSupplierName; quotation.supplier_estimation = model.nSupplierEstimation2.HasValue ? model.nSupplierEstimation2 : 0.00; quotation.supplier_name2 = model.sSupplierName2; quotation.supplier_estimation3 = model.nSupplierEstimation3.HasValue ? model.nSupplierEstimation3 : 0.00; quotation.supplier_name3 = model.sSupplierName3; quotation.payment_received_date = this.ConvertDateStringFormat(model.dPaymentRecdDate, DATEPICKER_DATE_FORMAT); quotation.tender_number = model.sTenderNumber; quotation.direct_labour = model.bIsDirectLabour; quotation.direct_labour_cost = model.nDirectLabourCost.HasValue ? model.nDirectLabourCost : 0.00; quotation.billing_date = this.ConvertDateStringFormat(model.dBillingDate, DATEPICKER_DATE_FORMAT); quotation.confirm_date = this.ConvertDateStringFormat(model.dConfirmDate, DATEPICKER_DATE_FORMAT); quotation.invoice = model.sInvoiceNumber; quotation.invoice_date = this.ConvertDateStringFormat(model.dInvoiceDate, DATEPICKER_DATE_FORMAT); quotation.minor_work = model.sMinorWorkExtension; quotation.minor_work_currency = model.nMinorWork.HasValue ? model.nMinorWork : 0.00; quotation.gp = model.nGP.HasValue ? model.nGP : 0.00; quotation.last_update = DateTime.Now; quotation.remark = model.sRemark; quotation.update_user_id = (int)member.infoBySession("id"); quotation.issue_date = this.ConvertDateStringFormat(model.dIssueDate, DATEPICKER_DATE_FORMAT); this._db.SaveChanges(); #endregion Update Quotation #region Delete Original Quotation Items var quotationItemsObject = (from qi in this._db.recsys_quotation_items join r in this._db.recsys_relate on qi.id equals r.id2 where r.id1 == model.nQuotationID && r.table1 == "quotation" && r.table2 == "quotation_items" select new { qi, r }).ToList(); foreach (var qio in quotationItemsObject) { this._db.recsys_quotation_items.DeleteObject(qio.qi); this._db.recsys_relate.DeleteObject(qio.r); this._db.SaveChanges(); } #endregion Delete Original Quotation Items } quotationID = quotation.id; #region Create Quotation Items if (items != null && items.Count() > 0) { int sequence = 1; foreach (QuotationQuickCreateQuotationItemModel item in items) { #region Validation if (string.IsNullOrWhiteSpace(item.sCode) && string.IsNullOrWhiteSpace(item.sDetail) && string.IsNullOrWhiteSpace(item.sDetailChi)) continue; #endregion Validation #region Create Quotation Item recsys_quotation_items quotationItem = new recsys_quotation_items { nSequence = sequence, code = string.IsNullOrEmpty(item.sCode) ? string.Empty : item.sCode.Trim(), detail = string.IsNullOrEmpty(item.sDetailChi) ? null : item.sDetailChi.Trim(), detail2 = string.IsNullOrEmpty(item.sDetail) ? null : item.sDetail.Trim(), price = item.nPrice.HasValue ? item.nPrice.Value : 0.00, last_update = DateTime.Now, update_user_id = (int)member.infoBySession("id") }; this._db.recsys_quotation_items.AddObject(quotationItem); this._db.SaveChanges(); #endregion Create Quotation Item #region Create Relate Record recsys_relate relation = new recsys_relate { table1 = "quotation", table2 = "quotation_items", id1 = quotation.id, id2 = quotationItem.id }; this._db.recsys_relate.AddObject(relation); this._db.SaveChanges(); #endregion Create Relate Record sequence++; } } #endregion Create Quotation Items } catch { isSuccess = false; } return Json( new { isSuccess = isSuccess, quotationID = quotationID }); }
public ActionResult Edit() { Validator _val = new Validator(); string id = Common.doPost("id"); string relate_id = Common.doPost("relate_id"); string table_name = Common.doPost("table_name"); string user_id = Common.doPost("user_id"); string supplier_id = Common.doPost("supplier_id"); string center = Common.doPost("center"); string cost_id = Common.doPost("cost_id"); string invoice = Common.doPost("invoice"); string price1 = Common.doPost("price1"); string price2 = Common.doPost("price2"); string account_date = Common.doPost("account_date2"); string remark = Common.doPost("remark"); string status = Common.doPost("status2"); string oper = Common.doPost("oper"); string sql; if(oper != "del") { if(oper == "edit") { _val.val(id, new String[] { "req", "int" }); } _val.val(relate_id, new String[] { "req", "int" }); _val.val(table_name, "req"); _val.val(status, new String[] { "req", "int", "get=0", "let=1" }); _val.val(cost_id, new String[] { "req", "int" }); if (user_id != "0") { _val.val(user_id, new String[] { "req", "int" }); int user = Convert.ToInt32(user_id); int user_exist = (from u in this._db.recsys_users where u.status == 1 && u.id == user && u.type == 4 select u).Count(); if (user_exist == 0) { _val.setValStatus(false); } } else { _val.val(supplier_id, new String[] { "req", "int" }); int supplier = Convert.ToInt32(supplier_id); int supplier_exist = (from s in this._db.recsys_supplier where s.status == 1 && s.id == supplier select s).Count(); if (supplier_exist == 0) { _val.setValStatus(false); } } if(_val.getValStatus()) { Member _member = new Member("users"); Hashtable data = new Hashtable() { { "user_id", user_id }, { "supplier_id", supplier_id }, { "cost_id", cost_id }, { "center", center }, { "invoice", invoice }, { "price1", price1 }, { "price2", price2 }, { "account_date", account_date }, { "remark", remark }, { "status", status }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") } }; if(oper == "edit") { sql = Common.doUpdate(data, "costs", "id = '" + id + "'"); } else { sql = Common.doInsert(data, "costs"); this._db.ExecuteStoreCommand(sql); id = (from cs in this._db.recsys_costs orderby cs.id descending select cs.id).FirstOrDefault().ToString(); data = new Hashtable() { { "id1", id }, { "id2", relate_id }, { "table1", "costs" }, { "table2", table_name } }; sql = Common.doInsert(data, "relate"); } } else { return Content(Common.json_encode(false)); } } else { sql = Common.doDelete("relate", "id1 = '" + id + "' AND table1 = 'costs'"); this._db.ExecuteStoreCommand(sql); sql = Common.doDelete("costs", "id = '" + id + "'"); } this._db.ExecuteStoreCommand(sql); return Content(Common.json_encode(true)); }
public ActionResult SaveEdit(QuotationPackagesRecord model) { bool isSuccess = false; recsys_quotation_packages record = this._db.recsys_quotation_packages.FirstOrDefault(qp => qp.id == model.id); //# validation if (record == null) throw new RecordNotFoundException(); if (!record.update_date.HasValue) throw new ImproperDataException(); int test = model.FetchRecordTime.CompareTo(record.update_date.Value); if (model.FetchRecordTime.CompareTo(record.update_date.Value) < -1) throw new OptimisticConcurrencyException("資料已被其他使用者更新"); var quotationPackages = from qp in this._db.recsys_quotation_packages where qp.status == 1 select qp; foreach (recsys_quotation_packages quotationPackage in quotationPackages) { if (!string.IsNullOrEmpty(model.code) && model.code.Trim().ToUpper() == quotationPackage.code.Trim().ToUpper() && (model.id!=quotationPackage.id)) { string message = "已有Quotation Package (" + model.code.Trim().ToUpper() + ")"; return Json( new { isSuccess = isSuccess, message = message }); } } if (string.IsNullOrEmpty(model.code)) { return Json( new { isSuccess = isSuccess, message = "必須輸入Code" }); } else if (string.IsNullOrEmpty(model.districtID.ToString())) { return Json( new { isSuccess = isSuccess, message = "必須選擇地區" }); } else { record.package_name = (model.packageName == null) ? "" : model.packageName.Trim(); record.code = model.code.Trim() ?? ""; record.district_id = model.districtID; record.customer_type = model.customerTypeID; record.remark = (model.remark == null)? "" : model.remark.Trim(); record.update_date = DateTime.Now; Member _member = new Member("users"); record.update_by = (int)_member.infoBySession("id"); } try { this._db.SaveChanges(); isSuccess = true; } catch (OptimisticConcurrencyException) { //# log down } return Json( new { isSuccess = isSuccess }); }
public ActionResult AddSave(QuotationRecord data) { Member member; recsys_customers masterCustomer; recsys_relate_customers customerData; recsys_quotation quotation; //# validation if (!String.IsNullOrEmpty(data.invoice) && data.dummy) { data.SaveResult.WarningMessage = "請刪除Invoice No或取消選取'有Dummy Invoice'"; data.SaveResult.SavedSuccessfully = false; return Json(data); } if (!String.IsNullOrEmpty(data.minor_work)) { if (data.minor_work.Length > 3) { data.SaveResult.WarningMessage = "請修改Minor Work至3字以內"; data.SaveResult.SavedSuccessfully = false; return Json(data); } } //# validation if (data.MasterCustomerID < 0) throw new SystemException("Invalid Entity ID"); //# get old master customer record masterCustomer = this._db.recsys_customers.FirstOrDefault(theCustomer => theCustomer.id == data.MasterCustomerID); //# validation if (masterCustomer == null) throw new RecordNotFoundException(); member = new Member("users"); bool createNewDistrict = false; if (!string.IsNullOrEmpty(data.WorkingDistrictName)) { recsys_district workingDistrict = this._db.recsys_district.Where(x => x.name.Trim().ToUpper().Equals(data.WorkingDistrictName.Trim().ToUpper())).SingleOrDefault(); if (workingDistrict != null) { data.district2 = workingDistrict.id; data.group_id = workingDistrict.group_id; } else createNewDistrict = true; } if (createNewDistrict) { recsys_district addNewDistrict = new recsys_district() { code = data.WorkingDistrictName.Trim(), name = data.WorkingDistrictName.Trim(), group_id = this._db.recsys_group.Where(x => x.name.Equals("Unknown Group For System Migration")).SingleOrDefault().id, region = 4, status = 1, last_update = DateTime.Now, update_user_id = (int)member.infoBySession("id") }; this._db.recsys_district.AddObject(addNewDistrict); this._db.SaveChanges(); data.district2 = this._db.recsys_district.Where(x => x.name.Equals(data.WorkingDistrictName.Trim())).SingleOrDefault().id; data.group_id = this._db.recsys_district.Where(x => x.name.Equals(data.WorkingDistrictName.Trim())).SingleOrDefault().group_id; } createNewDistrict = false; if (!string.IsNullOrEmpty(data.MailingDistrictName)) { recsys_district mailingDistrict = this._db.recsys_district.Where(x => x.name.Trim().ToUpper().Equals(data.MailingDistrictName.Trim().ToUpper())).SingleOrDefault(); if (mailingDistrict != null) { data.district1 = mailingDistrict.id; data.group_id = mailingDistrict.group_id; } else createNewDistrict = true; } if (createNewDistrict) { recsys_district addNewDistrict = new recsys_district() { code = data.MailingDistrictName.Trim(), name = data.MailingDistrictName.Trim(), group_id = this._db.recsys_group.Where(x => x.name.Equals("Unknown Group For System Migration")).SingleOrDefault().id, region = 4, status = 1, last_update = DateTime.Now, update_user_id = (int)member.infoBySession("id") }; this._db.recsys_district.AddObject(addNewDistrict); this._db.SaveChanges(); data.district1 = this._db.recsys_district.Where(x => x.name.Equals(data.MailingDistrictName.Trim())).SingleOrDefault().id; data.group_id = this._db.recsys_district.Where(x => x.name.Equals(data.MailingDistrictName.Trim())).SingleOrDefault().group_id; } //# mapping customerData = new recsys_relate_customers() { address1 = data.address1, address2 = data.address2, center = masterCustomer.center, code = masterCustomer.code, contact = data.contact, customer_code = masterCustomer.customer_code, customer_id = masterCustomer.id, district1 = data.district1, district2 = data.district2, email = data.email, fax1 = data.fax1, fax2 = data.fax2, group_id = data.group_id, manual_input_code = masterCustomer.manual_input_code, name = data.name, chi_name = data.chi_name, prefix = masterCustomer.prefix, relate_type = (int)Rec_System.Models.Customers.CustomerDataRelateType.Maintenance, reference_number = masterCustomer.reference_number, remark = data.remark, tel1 = data.tel1, tel2 = data.tel2, title = (byte)data.title, type = (byte)masterCustomer.type }; this._db.recsys_relate_customers.AddObject(customerData); quotation = new recsys_quotation() { dummy = (byte)(data.dummy ? 1 : 0), dummy_date = DateChecking(data.dummy_date), initial = data.initial, lang = data.lang, order_number = data.order_number, number = data.number, subcon_estimation = data.subcon_estimation.HasValue ? data.subcon_estimation : 0.00, subcon_name = data.subcon_name, subcon_estimation2 = data.subcon_estimation2.HasValue ? data.subcon_estimation2 : 0.00, subcon_name2 = data.subcon_name2, subcon_estimation3 = data.subcon_estimation3.HasValue ? data.subcon_estimation3 : 0.00, subcon_name3 = data.subcon_name3, supervision = data.supervision.HasValue ? data.supervision : 0.00, supplier_name = data.supplier_name, supplier_name2 = data.supplier_name2, supplier_name3 = data.supplier_name3, supplier_estimation = data.supplier_estimation.HasValue ? data.supplier_estimation : 0.00, supplier_estimation2 = data.supplier_estimation2.HasValue ? data.supplier_estimation2 : 0.00, supplier_estimation3 = data.supplier_estimation3.HasValue ? data.supplier_estimation3 : 0.00, supplier_id = data.supplier_id.HasValue ? data.supplier_id : 0.00, material_estimation2 = data.material_estimation2.HasValue ? data.material_estimation2 : 0.00, material_estimation3 = data.material_estimation3.HasValue ? data.material_estimation3 : 0.00, payment_received_date = DateChecking(data.payment_received_date), tender_number = data.tender_number, direct_labour = data.direct_labour, direct_labour_cost = data.direct_labour_cost.HasValue ? data.direct_labour_cost : 0.00, billing_date = DateChecking(data.billing_date), confirm_date = DateChecking(data.confirm_date), create_date = DateTime.Now, invoice = data.invoice, invoice_date = DateChecking(data.billing_date), minor_work = data.minor_work, minor_work_currency = data.minor_work_currency.HasValue ? data.minor_work_currency : 0.00, gp = data.gp.HasValue ? data.gp : 0.00, last_update = DateTime.Now, remark = data.remark2, status = (byte)data.status, update_user_id = (int)member.infoBySession("id"), issue_date = DateChecking(data.issue_date) }; this._db.recsys_quotation.AddObject(quotation); try { this._db.SaveChanges(); this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, customerData); this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, quotation); quotation.customer_id = customerData.id; this._db.SaveChanges(); data.id = quotation.id; data.SaveResult.SavedSuccessfully = true; } catch (OptimisticConcurrencyException) { //# log down } return Json(data); }
public ActionResult Edit() { Validator _val = new Validator(); string id = Common.doPost("id"); string name = Common.doPost("name"); string type_id = Common.doPost("type_id2"); string user_group = Common.doPost("user_group"); string center = Common.doPost("center"); string grade = Common.doPost("grade2"); string employee_number = Common.doPost("employee_number"); string username = Common.doPost("username"); string oldpassword = Common.doPost("oldpassword"); string password = Common.doPost("password"); string password2 = Common.doPost("password2"); string country_id = Common.doPost("country_id2"); string phone_number = Common.doPost("phone_number"); string email = Common.doPost("email"); string status = Common.doPost("status2"); string oper = Common.doPost("oper"); string encryptedOldPassword = ""; string encryptedOldPasswordDB = ""; Member _member = new Member("users"); if(oper != "del") { if(oper == "edit") { _val.val(id, new String[] { "req", "int" }); if (!String.IsNullOrWhiteSpace(password) || !String.IsNullOrWhiteSpace(password2)) { int userID = Convert.ToInt32(id); encryptedOldPasswordDB = (from u in this._db.recsys_users where u.id == userID select u.password).FirstOrDefault(); string salt = encryptedOldPasswordDB.Substring(0, 20); encryptedOldPassword = _member.encrypt(oldpassword, salt); if (!encryptedOldPassword.Equals(encryptedOldPasswordDB)) return Content("oldPasswordNotMatch"); } } _val.val(name, "req"); _val.val(type_id, new String[] { "req", "int" }); _val.val(user_group, new String[] { "req", "int", "get=0" }); _val.val(center, new String[] { "req", "int" }); _val.val(country_id, new String[] { "req", "int" }); if (!string.IsNullOrWhiteSpace(phone_number)) _val.val(phone_number, "int"); if (email != null) { _val.val(email, "email"); } _val.val(status, new String[] { "req", "int", "get=0", "let=1" }); int t_id = Convert.ToInt32(type_id); Byte type = (from t in this._db.recsys_type where t.status == 1 && t.id == t_id select t.type).FirstOrDefault(); if (!String.IsNullOrWhiteSpace(username)) { if (_member.isExist(username, "username", oper != "edit" ? "" : "id != '" + id + "'")) { _val.setValStatus(false); } } if (!String.IsNullOrWhiteSpace(password) || !String.IsNullOrWhiteSpace(password2)) { _val.val(password, "req"); _val.val(password2, new String[] { "req", "equal=" + password }); } if (type == null || !this._ctr.Contains(center)) { _val.setValStatus(false); } if (this.isDuplicatePhoneNumber(phone_number, id, country_id)) { _val.setValStatus(false); } if(_val.getValStatus()) { grade = string.IsNullOrEmpty(grade) ? null : grade; Hashtable data = new Hashtable() { { "name", name }, { "type_id", type_id }, { "type", type }, { "user_group", user_group }, { "center", center }, { "username", username }, { "email", email }, { "status", status }, { "last_update", DateTime.Now.ToString("s") }, { "update_user_id", _member.infoBySession("id") }, { "employee_number", employee_number}, { "country_id", country_id }, { "phone_number", phone_number }, { "grade", grade } }; if(! String.IsNullOrWhiteSpace(password)) { data["password"] = password; } if(oper == "edit") { _member.update(data, id, "id"); } else { _member.insert(data); id = (from m in this._db.recsys_users orderby m.id descending select m.id).FirstOrDefault().ToString(); } } else { return Content("false"); } } else { this._db.ExecuteStoreCommand(Common.doDelete("relate", "id2 = '" + id + "' AND table1 = 'group' AND table2 = 'users'")); _member.delete(Convert.ToInt32(id)); Common.delDir("Upload/users/" + id + "/"); } return Content(id); }
public ActionResult CloneQuotation(int? id) { //# validation if (!id.HasValue) return Json(new { bIsSuccessful = false }); bool isSuccessful = false; Member member = new Member("users"); int newQuotationID = 0; try { //# get existing quotation recsys_quotation existingQuotation = this._db.recsys_quotation.FirstOrDefault(theQuotation => theQuotation.id == id.Value); if (existingQuotation != null) { //# get existing quotation customer data recsys_relate_customers existingQuotationCustomerData = this._db.recsys_relate_customers.FirstOrDefault(theCustomerData => theCustomerData.id == existingQuotation.customer_id); if (existingQuotationCustomerData != null) { //# get existing quotation items IEnumerable<recsys_quotation_items> existingQuotationItems = from r in this._db.recsys_relate join qi in this._db.recsys_quotation_items on r.id2 equals qi.id where r.id1 == id.Value && r.table1 == "quotation" && r.table2 == "quotation_items" select qi; //# construct new customer data recsys_relate_customers newQuotationCustomerData = CustomersController.CopyCustomerData(existingQuotationCustomerData); //# construct new quotation items recsys_quotation_items[] newQuotationItems = existingQuotationItems.Select(theItem => QuotationsController.CopyQuotationItem(theItem)).ToArray(); this._db.recsys_relate_customers.AddObject(newQuotationCustomerData); foreach (recsys_quotation_items item in newQuotationItems) { item.last_update = DateTime.Now; item.update_user_id = (int)member.infoBySession("id"); this._db.recsys_quotation_items.AddObject(item); } //# save customer data this._db.SaveChanges(); //# load new customer data this._db.Refresh(RefreshMode.StoreWins, newQuotationCustomerData); //# load new items this._db.Refresh(RefreshMode.StoreWins, newQuotationItems); if (newQuotationCustomerData.id > 0) { //# construct new quotation recsys_quotation newQuotation = new recsys_quotation(); newQuotation.create_date = DateTime.Now; newQuotation.customer_id = newQuotationCustomerData.id; newQuotation.last_update = DateTime.Now; newQuotation.update_user_id = (int)member.infoBySession("id"); newQuotation.status = 1; newQuotation.issue_date = DateTime.Now.Date; if (existingQuotation.lang != 0) newQuotation.lang = existingQuotation.lang; else newQuotation.lang = 1; //default chinese this._db.recsys_quotation.AddObject(newQuotation); //# save quotation this._db.SaveChanges(); //# load new quotation this._db.Refresh(RefreshMode.StoreWins, newQuotation); newQuotationID = newQuotation.id; if (newQuotation.id > 0 && newQuotationItems.Count(theItem => theItem.id > 0) > 0) { //# construct relations IEnumerable<recsys_relate> relations = newQuotationItems.Where(theItem => theItem.id > 0) .Select(theItem => new recsys_relate() { id1 = newQuotation.id, id2 = theItem.id, table1 = "quotation", table2 = "quotation_items" }); foreach (recsys_relate relation in relations) this._db.recsys_relate.AddObject(relation); //# save relations this._db.SaveChanges(); isSuccessful = true; } else isSuccessful = true; } } } //# clone quotation //# save changes } catch (OptimisticConcurrencyException) { //# log down } return Json(new { bIsSuccessful = isSuccessful, iNewID = newQuotationID }); }