public void ManageCustomers(bool creating, QueryCustomer queryCustomer) { int id = queryCustomer.CustomId; string location = queryCustomer.Location; Customer c = creating ? new Customer() : queryCustomer.Customer; c.CustomId = id; c.Name = queryCustomer.Name; c.BirthDate = queryCustomer.BirthDate; c.LocationId = null; if (!string.IsNullOrWhiteSpace(location)) { Location loc = locationRepo.FirstOrDefault(x => x.Name == location); if (loc != null) { c.LocationId = loc.Id; } else { int locatId = locationRepo.Collection().Count() + 1; locationRepo.Insert(new Location { Id = locatId, Name = location }); locationRepo.Commit(); c.LocationId = locatId; } } InsertUpdateCommit(creating, c, customerRepo); }
public ActionResult Update(QueryCustomer customer) { if (!ModelState.IsValid) { OverrideErrorMessage(); return(View(customer)); } contextManager.ManageCustomers(false, customer); return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Lookup(Guid id, [FromQuery] bool includeSuggestions) { var query = new QueryCustomer(id) { IncludedSuggestions = includeSuggestions }; CustomerInfo info = await _messaging.DispatchAsync(query); if (info == null) { return(NotFound("Contact not registered.")); } return(Ok(CustomerResource.FromEntity(info))); }
internal void ManageCustomers(bool isCreating) { inAppBehavior.MenuItemEntry("Register new Customer", "Update Customer", isCreating); int id = reader.ReadInt("Client ID: "); string name = reader.ReadString("Client Name: "); DateTime birthDate = reader.ReadDate("Birth Date: "); string location = reader.ReadString("Location: "); QueryCustomer queryCustomer = new QueryCustomer { CustomId = id, Name = name, BirthDate = birthDate, Location = location, IsCreating = isCreating }; PushModel(queryCustomer, isCreating, contextManager.ManageCustomers, ManageCustomers); }
public async Task <CustomerInfo> FindCustomer(QueryCustomer query) { Customer customer = await _customerRepo.ReadAsync(query.Id); if (customer == null) { return(null); } Address primaryAddress = customer.GetPrimaryAddress(); var info = new CustomerInfo { Customer = customer }; if (query.IncludedSuggestions && primaryAddress != null) { info.Suggestions = await _suggestionRepo.LookupSuggestedAutos(primaryAddress.State, customer.Age); } return(info); }
/// <summary> /// 非批量保存车辆客户信息 /// </summary> /// <param name="customerArr">车辆客户信息</param> /// <param name="updateCount">更新条数</param> /// <returns></returns> private static bool SaveCustomerNotBatch(QueryCustomer.customer[] customerArr, ref int updateCount) { string nowTicks = Common.LocalDateTimeToUtcLong(GlobalStaticObj_Server.Instance.CurrentDateTime).ToString(); int customerIndex = 0;//列表索引 int customerCount = 10000;//每批执行条数 //customerCount = customerArr.Count(); int customerSum = customerArr.Count() / customerCount + 1;//执行批数 //int contactSum = 3; bool flag = true;//执行结果 DateTime startDate = DateTime.Now; YuTongDic dic = new YuTongDic(); //客户 DataTable dtCustomer = DBHelper.GetTable("获取车辆客户ID", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_customer", "cust_id,cust_code", null, null, null); #region 生成表列 DataTable dt = new DataTable(); List<DataRow> listTbCustomer = new List<DataRow>(); dt.Columns.Add(new DataColumn("cust_crm_guid", typeof(string))); dt.Columns.Add(new DataColumn("cust_id", typeof(string))); dt.Columns.Add(new DataColumn("cust_code", typeof(string))); dt.Columns.Add(new DataColumn("cust_name", typeof(string))); dt.Columns.Add(new DataColumn("province", typeof(string))); dt.Columns.Add(new DataColumn("city", typeof(string))); dt.Columns.Add(new DataColumn("county", typeof(string))); dt.Columns.Add(new DataColumn("cust_address", typeof(string))); dt.Columns.Add(new DataColumn("zip_code", typeof(string))); dt.Columns.Add(new DataColumn("cust_phone", typeof(string))); dt.Columns.Add(new DataColumn("cust_fax", typeof(string))); dt.Columns.Add(new DataColumn("cust_email", typeof(string))); dt.Columns.Add(new DataColumn("cust_website", typeof(string))); dt.Columns.Add(new DataColumn("credit_rating", typeof(string))); dt.Columns.Add(new DataColumn("enable_flag", typeof(string))); dt.Columns.Add(new DataColumn("data_source", typeof(string))); dt.Columns.Add(new DataColumn("cust_relation", typeof(string))); dt.Columns.Add(new DataColumn("indepen_legalperson", typeof(string))); dt.Columns.Add(new DataColumn("market_segment", typeof(string))); dt.Columns.Add(new DataColumn("institution_code", typeof(string))); dt.Columns.Add(new DataColumn("com_constitution", typeof(string))); dt.Columns.Add(new DataColumn("registered_capital", typeof(string))); dt.Columns.Add(new DataColumn("agency", typeof(string))); dt.Columns.Add(new DataColumn("status", typeof(string))); dt.Columns.Add(new DataColumn("sap_code", typeof(string))); dt.Columns.Add(new DataColumn("business_scope", typeof(string))); dt.Columns.Add(new DataColumn("ent_qualification", typeof(string))); dt.Columns.Add(new DataColumn("create_by", typeof(string))); dt.Columns.Add(new DataColumn("create_time", typeof(long))); #endregion for (int i = 0; i < customerSum; i++) { List<SysSQLString> list = new List<SysSQLString>(); dt.Rows.Clear(); listTbCustomer.Clear(); for (int y = customerIndex; y < customerCount; y++) { int index = i * customerCount + y; if (index >= customerArr.Count()) { break; } QueryCustomer.customer item = customerArr[index]; //bool isContactExist = DBHelper.IsExist("判断车辆客户信息是否存在", "tb_customer", "cust_code='" + item.cust_code + "'"); string custID = null; if (dtCustomer != null && dtCustomer.Rows.Count > 0) { DataRow[] drs = dtCustomer.Select("cust_code='" + item.cust_code + "'"); if (drs.Count() > 0) { custID = drs[0]["cust_id"].ToString(); } } string credit_rating = dic.GetLocalDicID("credit_rating", item.credit_rating); string cust_relation = dic.GetLocalDicID("cust_relation", item.cust_relation); string com_constitution = dic.GetLocalDicID("com_constitution", item.com_constitution); string ent_qualification = dic.GetLocalDicID("ent_qualification", item.ent_qualification); string market_segment = dic.GetLocalDicID("market_segment", item.market_segment); if (!string.IsNullOrEmpty(custID)) { #region 更新语句 SysSQLString sysSQLString = new SysSQLString(); sysSQLString.cmdType = CommandType.Text; sysSQLString.Param = new Dictionary<string, string>(); sysSQLString.Param.Add("business_scope", item.business_scope); StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_customer set "); strSql.AppendFormat(" cust_crm_guid= '{0}' , ", item.cust_crm_guid); strSql.AppendFormat(" cust_code= '{0}' , ", item.cust_code); strSql.AppendFormat(" cust_name= '{0}' , ", item.cust_name); strSql.AppendFormat(" province= '{0}' , ", item.province); strSql.AppendFormat(" city= '{0}' , ", item.city); strSql.AppendFormat(" county= '{0}' , ", item.county); strSql.AppendFormat(" cust_address= '{0}' , ", item.cust_address); strSql.AppendFormat(" zip_code= '{0}' , ", item.zip_code); strSql.AppendFormat(" cust_phone= '{0}' , ", item.cust_phone); strSql.AppendFormat(" cust_fax= '{0}' , ", item.cust_fax); strSql.AppendFormat(" cust_email= '{0}' , ", item.email); strSql.AppendFormat(" cust_website= '{0}' , ", item.cust_website); strSql.AppendFormat(" credit_rating= '{0}' , ", credit_rating); strSql.AppendFormat(" enable_flag= '{0}' , ", (int)DataSources.EnumEnableFlag.USING); strSql.AppendFormat(" data_source= '{0}' , ", (int)DataSources.EnumDataSources.YUTONG); strSql.AppendFormat(" cust_relation= '{0}' , ", cust_relation); strSql.AppendFormat(" indepen_legalperson= '{0}' , ", item.indepen_legalperson); strSql.AppendFormat(" market_segment= '{0}' , ", market_segment); strSql.AppendFormat(" institution_code= '{0}' , ", item.institution_code); strSql.AppendFormat(" com_constitution= '{0}' , ", com_constitution); strSql.AppendFormat(" registered_capital= '{0}' , ", item.registered_capital); strSql.AppendFormat(" agency= '{0}' , ", item.agency); strSql.AppendFormat(" status= '{0}' , ", item.status == "0" ? "1" : "0"); strSql.AppendFormat(" sap_code= '{0}' , ", item.sap_code); strSql.Append(" business_scope= @business_scope , "); strSql.AppendFormat(" ent_qualification= '{0}' , ", ent_qualification); strSql.AppendFormat(" update_by= '{0}' , ", GlobalStaticObj_Server.Instance.UserID); strSql.AppendFormat(" update_time={0} ", nowTicks); strSql.AppendFormat(" where cust_id='{0}' ", custID); sysSQLString.sqlString = strSql.ToString(); list.Add(sysSQLString); #endregion } else { #region 插入语句 #region 验证字段长度 //string file = string.Empty; //if (item.zip_code.Length > 5) //{ // file = "zip_code"; //} //if (item.cust_crm_guid.Length > 40) //{ // file = "cust_crm_guid"; //} //if (item.cust_code.Length > 30) //{ // file = "cust_code"; //} //if (item.cust_name.Length > 100) //{ // file = "cust_name"; //} //if (item.province.Length > 40) //{ // file = "province"; //} //if (item.city.Length > 40) //{ // file = "city"; //} //if (item.county.Length > 40) //{ // file = "county"; //} //if (item.cust_address.Length > 100) //{ // file = "cust_address"; //} //if (item.cust_phone.Length > 15) //{ // file = "cust_phone"; //} //if (item.cust_fax.Length > 15) //{ // file = "cust_fax"; //} //if (item.email.Length > 30) //{ // file = "email"; //} //if (item.cust_website.Length > 100) //{ // file = "cust_website"; //} //if (credit_rating.Length > 40) //{ // file = "credit_rating"; //} //if (item.indepen_legalperson.Length > 5) //{ // file = "indepen_legalperson"; //} //if (cust_relation.Length > 40) //{ // file = "cust_relation"; //} //if (market_segment.Length > 40) //{ // file = "market_segment"; //} //if (item.institution_code.Length > 50) //{ // file = "institution_code"; //} //if (com_constitution.Length > 40) //{ // file = "com_constitution"; //} //if (item.registered_capital.Length > 20) //{ // file = "registered_capital"; //} //if (item.agency.Length > 30) //{ // file = "agency"; //} //if (item.sap_code.Length > 50) //{ // file = "sap_code"; //} //if (item.business_scope.Length > 500) //{ // file = "business_scope"; //} //if (ent_qualification.Length > 40) //{ // file = "ent_qualification"; //} //if (!string.IsNullOrEmpty(file)) //{ // file = ""; //} #endregion DataRow dr = dt.NewRow(); dr["cust_crm_guid"] = item.cust_crm_guid; dr["cust_id"] = Guid.NewGuid().ToString(); dr["cust_code"] = item.cust_code; dr["cust_name"] = item.cust_name; dr["province"] = item.province; dr["city"] = item.city; dr["county"] = item.county; dr["cust_address"] = item.cust_address; dr["zip_code"] = item.zip_code; dr["cust_phone"] = item.cust_phone; dr["cust_fax"] = item.cust_fax; dr["cust_email"] = item.email; dr["cust_website"] = item.cust_website; dr["credit_rating"] = credit_rating; dr["enable_flag"] = ((int)DataSources.EnumEnableFlag.USING).ToString(); dr["data_source"] = ((int)DataSources.EnumDataSources.YUTONG).ToString(); dr["cust_relation"] = cust_relation; dr["indepen_legalperson"] = item.indepen_legalperson; dr["market_segment"] = market_segment; dr["institution_code"] = item.institution_code; dr["com_constitution"] = com_constitution; dr["registered_capital"] = item.registered_capital; dr["agency"] = item.agency; dr["status"] = item.status == "0" ? "1" : "0"; dr["sap_code"] = item.sap_code; dr["business_scope"] = item.business_scope; dr["ent_qualification"] = ent_qualification; dr["create_by"] = GlobalStaticObj_Server.Instance.UserID; dr["create_time"] = nowTicks; //dt.Rows.Add(dr); listTbCustomer.Add(dr); #endregion } customerArr[index] = null; } //flag = DBHelper.BatchExeSQLMultiByTrans("宇通:同步车辆客户信息", list); //flag = DBHelper.BatchExeSQLStringMultiByTrans("tb_customer", listTbCustomer); flag = DBHelper.SqlBulkByTransNoLogNoBackUp("同步车辆客户信息", GlobalStaticObj_Server.Instance.MainAccCode, "tb_customer", listTbCustomer); if (!flag) { break; } if (list.Count > 0) { flag = DBHelper.BatchExeSQLStrMultiByTransNoLogNoBackup("", GlobalStaticObj_Server.Instance.MainAccCode, list); if (!flag) { break; } } } SysConfig sysConfig = new SysConfig(); sysConfig.UpdateLastTime("CustomerLastTime"); updateCount += customerArr.Count(); dtCustomer = null;//释放 dic = null; DateTime endDate = DateTime.Now; TimeSpan span = endDate - startDate; return flag; }
/// <summary> 保存车辆客户信息 /// </summary> /// <param name="customerArr">车辆客户信息</param> /// <returns>True OR False</returns> private static bool SaveCustomer(QueryCustomer.customer[] customerArr) { string nowTicks = Common.LocalDateTimeToUtcLong(GlobalStaticObj_Server.Instance.CurrentDateTime).ToString(); List<SysSQLString> list = new List<SysSQLString>(); foreach (QueryCustomer.customer item in customerArr) { SysSQLString sysSQLString = new SysSQLString(); sysSQLString.cmdType = CommandType.Text; sysSQLString.Param = new Dictionary<string, string>(); StringBuilder strSql = new StringBuilder(); bool isContactExist = DBHelper.IsExist("判断车辆客户信息是否存在", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_customer", "cust_code='" + item.cust_code + "'"); if (isContactExist) { #region 更新语句 strSql.Append("update tb_customer set "); strSql.Append(" cust_crm_guid= @cust_crm_guid , "); strSql.Append(" cust_code= @cust_code , "); strSql.Append(" cust_name= @cust_name , "); strSql.Append(" province= @province , "); strSql.Append(" city= @city , "); strSql.Append(" county= @county , "); strSql.Append(" cust_address= @cust_address , "); strSql.Append(" zip_code= @zip_code , "); strSql.Append(" cust_phone= @cust_phone , "); strSql.Append(" cust_fax= @cust_fax , "); strSql.Append(" cust_email= @cust_email , "); strSql.Append(" cust_website= @cust_website , "); strSql.Append(" credit_rating= @credit_rating , "); strSql.Append(" enable_flag= @enable_flag , "); strSql.Append(" data_source= @data_source , "); strSql.Append(" cust_relation= @cust_relation , "); strSql.Append(" indepen_legalperson= @indepen_legalperson , "); strSql.Append(" market_segment= @market_segment , "); strSql.Append(" institution_code= @institution_code , "); strSql.Append(" com_constitution= @com_constitution , "); strSql.Append(" registered_capital= @registered_capital , "); strSql.Append(" agency= @agency , "); strSql.Append(" status= @status , "); strSql.Append(" sap_code= @sap_code , "); strSql.Append(" business_scope= @business_scope , "); strSql.Append(" ent_qualification= @ent_qualification , "); strSql.Append(" update_by= @update_by , "); strSql.Append(" update_time= @update_time "); strSql.Append(" where cust_code=@cust_code "); #endregion } else { #region 插入语句 strSql.Append("insert into tb_customer("); strSql.Append("cust_crm_guid,cust_id,cust_code,cust_name,province,city,county,cust_address,zip_code,cust_phone,cust_fax,cust_email,cust_website,credit_rating,enable_flag,data_source,cust_relation,indepen_legalperson,market_segment,institution_code,com_constitution,registered_capital,agency,status,sap_code,business_scope,ent_qualification,create_by,create_time,update_by,update_time"); strSql.Append(") values ("); strSql.Append("@cust_crm_guid,@cust_id,@cust_code,@cust_name,@province,@city,@county,@cust_address,@zip_code,@cust_phone,@cust_fax,@cust_email,@cust_website,@credit_rating,@enable_flag,@data_source,@cust_relation,@indepen_legalperson,@market_segment,@institution_code,@com_constitution,@registered_capital,@agency,@status,@sap_code,@business_scope,@ent_qualification,@create_by,@create_time,@update_by,@update_time) "); #endregion sysSQLString.Param.Add("cust_id", Guid.NewGuid().ToString()); sysSQLString.Param.Add("create_by", GlobalStaticObj_Server.Instance.UserID); sysSQLString.Param.Add("create_time", nowTicks); } #region 参数项 24 sysSQLString.sqlString = strSql.ToString(); sysSQLString.Param.Add("cust_crm_guid", item.cust_crm_guid); sysSQLString.Param.Add("cust_code", item.cust_code); sysSQLString.Param.Add("cust_name", item.cust_name); sysSQLString.Param.Add("province", item.province); sysSQLString.Param.Add("city", item.city); sysSQLString.Param.Add("county", item.county); sysSQLString.Param.Add("cust_address", item.cust_address); sysSQLString.Param.Add("zip_code", item.zip_code); sysSQLString.Param.Add("cust_phone", item.cust_phone); sysSQLString.Param.Add("cust_fax", item.cust_fax); sysSQLString.Param.Add("cust_email", item.email); sysSQLString.Param.Add("cust_website", item.cust_website); sysSQLString.Param.Add("credit_rating", WebServUtil.GetLocalDicID("credit_rating", item.credit_rating)); sysSQLString.Param.Add("cust_relation", WebServUtil.GetLocalDicID("cust_relation", item.cust_relation)); sysSQLString.Param.Add("indepen_legalperson", item.indepen_legalperson);//独立法人 true false sysSQLString.Param.Add("market_segment", item.market_segment); sysSQLString.Param.Add("institution_code", item.institution_code); sysSQLString.Param.Add("com_constitution", WebServUtil.GetLocalDicID("com_constitution", item.com_constitution)); sysSQLString.Param.Add("registered_capital", item.registered_capital); sysSQLString.Param.Add("agency", item.agency);//是否整车经销商 True False sysSQLString.Param.Add("status", item.status);//可用 0 停用 1 sysSQLString.Param.Add("sap_code", item.sap_code); sysSQLString.Param.Add("business_scope", item.business_scope); sysSQLString.Param.Add("ent_qualification", WebServUtil.GetLocalDicID("ent_qualification", item.ent_qualification)); sysSQLString.Param.Add("enable_flag", ((int)DataSources.EnumEnableFlag.USING).ToString()); sysSQLString.Param.Add("data_source", ((int)DataSources.EnumDataSources.YUTONG).ToString()); sysSQLString.Param.Add("update_by", GlobalStaticObj_Server.Instance.UserID); sysSQLString.Param.Add("update_time", nowTicks); #endregion sysSQLString.sqlString = strSql.ToString(); list.Add(sysSQLString); } bool flag = DBHelper.BatchExeSQLStringMultiByTrans("宇通:同步车辆客户信息", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, list); return flag; }