/// <summary> 车辆客户创建更新 /// </summary> /// <param name="contactModel">车辆客户实体</param> /// <returns>返回错误信息,如果不为空,则操作失败</returns> public static string UpLoadCustomer(tb_customer customerModel) { //如果没有接入码或者sap代码,则不调用接口 if (string.IsNullOrEmpty(GlobalStaticObj_YT.ClientID) || string.IsNullOrEmpty(GlobalStaticObj_YT.SAPCode)) { return ""; } #region 测试数据 //customerModel = new tb_customer(); //customerModel.cust_crm_guid = "f11397b4-d155-e411-b917-005056ad01ea"; //customerModel.cust_name = ""; //customerModel.cust_code = ""; //customerModel.province = ""; //customerModel.city = ""; //customerModel.county = ""; //customerModel.cust_address = ""; //customerModel.cust_relation = ""; //customerModel.zip_code = ""; //customerModel.cust_phone = ""; //customerModel.cust_fax = ""; //customerModel.cust_email = ""; //customerModel.cust_website = ""; //customerModel.indepen_legalperson = ""; //customerModel.market_segment = ""; //customerModel.institution_code = ""; //customerModel.ent_qualification = ""; //customerModel.com_constitution = ""; //customerModel.registered_capital = ""; //customerModel.business_scope = ""; //customerModel.credit_rating = ""; //customerModel.status = ""; //customerModel.agency = ""; //customerModel.sap_code = ""; #endregion string requestType = string.IsNullOrEmpty(customerModel.cust_crm_guid) ? "CREATE" : "UPDATE"; SUCustomer.customer customerServModel = new SUCustomer.customer(); customerServModel.cust_crm_guid = customerModel.cust_crm_guid; customerServModel.cust_name = customerModel.cust_name; customerServModel.cust_code = customerModel.cust_code; customerServModel.province = customerModel.province; customerServModel.city = customerModel.city; customerServModel.county = customerModel.county; customerServModel.cust_address = customerModel.cust_address; customerServModel.cust_relation = ""; customerServModel.zip_code = customerModel.zip_code; customerServModel.cust_phone = customerModel.cust_phone; customerServModel.cust_fax = customerModel.cust_fax; customerServModel.email = customerModel.cust_email; customerServModel.cust_website = customerModel.cust_website; customerServModel.indepen_legalperson = customerModel.indepen_legalperson;//独立法人 true false customerServModel.market_segment = customerModel.market_segment; customerServModel.institution_code = customerModel.institution_code; customerServModel.ent_qualification = ""; customerServModel.com_constitution = ""; customerServModel.registered_capital = customerModel.registered_capital; customerServModel.business_scope = customerModel.business_scope; customerServModel.credit_rating = ""; customerServModel.status = customerModel.status;//可用 0 停用 1 customerServModel.agency = customerModel.agency;//是否整车经销商 True False customerServModel.sap_code = customerModel.sap_code; //Utility.Log.Log.writeLineToLog("【车辆客户创建更新】\r\n" + Newtonsoft.Json.JsonConvert.SerializeObject(customerServModel), "接口"); GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("车辆客户创建更新", Newtonsoft.Json.JsonConvert.SerializeObject(customerServModel)); ServicePointManager.ServerCertificateValidationCallback = WebServUtil.ValidateServerCertificate; SUCustomer.clientInfo clientInfo = new SUCustomer.clientInfo(); clientInfo.clientID = GlobalStaticObj_YT.ClientID; clientInfo.serviceID = "customerSU"; SUCustomer.customerSUService serv = new SUCustomer.customerSUService(); string stationCode = Secret.Encrypt3DES_UTF8(GlobalStaticObj_YT.SAPCode, GlobalStaticObj_YT.KeySecurity_YT); string dateStr = Secret.Encrypt3DES_UTF8(GlobalStaticObj_Server.Instance.CurrentDateTime.ToString("yyyy-MM-dd HH:mm:ss"), GlobalStaticObj_YT.KeySecurity_YT); requestType = Secret.Encrypt3DES_UTF8(requestType, GlobalStaticObj_YT.KeySecurity_YT); clientInfo = WebServUtil.EncModel<SUCustomer.clientInfo>(clientInfo); customerServModel = WebServUtil.EncModel<SUCustomer.customer>(customerServModel); DateTime dtStart = GlobalStaticObj_Server.Instance.CurrentDateTime;//开始时间 SUCustomer.Result result = new SUCustomer.Result(); string message = string.Empty;//错误消息 try { result = serv.customerSU(stationCode, dateStr, requestType, customerServModel, clientInfo); } catch (InvalidOperationException ioe) { //Utility.Log.Log.writeLineToLog(ioe, "车辆客户"); GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("车辆客户创建更新", ioe); message = ioe.Message; } string state = Secret.Decrypt3DES_UTF8(result.state, GlobalStaticObj_YT.KeySecurity_YT); if (state == "F") { string errMsg = Secret.Decrypt3DES_UTF8(result.errorMsg, GlobalStaticObj_YT.KeySecurity_YT); //Utility.Log.Log.writeLineToLog("【车辆客户创建更新】\r\n" + errMsg, "接口"); GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("车辆客户创建更新", errMsg); return "宇通接口错误:" + errMsg; } else { Dictionary<string, string> dicFields = new Dictionary<string, string>(); string cust_crm_guid = Secret.Decrypt3DES_UTF8(result.cust_crm_guid, GlobalStaticObj_YT.KeySecurity_YT); //Utility.Log.Log.writeLineToLog("【车辆客户创建更新】返回\r\n" + cust_crm_guid, "接口"); GlobalStaticObj_Server.YTInterfaceLogService.WriteLog("车辆客户创建更新返回", cust_crm_guid); dicFields.Add("cust_crm_guid", cust_crm_guid); bool flag = DBHelper.Submit_AddOrEdit("更新车辆客户:宇通cust_crm_guid", GlobalStaticObj_Server.DbPrefix + GlobalStaticObj_Server.Instance.MainAccCode, "tb_customer", "cust_id", customerModel.cust_id, dicFields); DateTime dtEnd = GlobalStaticObj_Server.Instance.CurrentDateTime;//结束时间 WebServUtil.WriteInterficeSyncLog(DataSources.EnumInterfaceType.BusCustomer, DataSources.EnumExternalSys.YTCRM, DataSources.EnumSyncDirection.UpLoad, "tb_customer", dtStart, dtEnd, 1, message); return flag ? "" : "DB错误:更新车辆客户失败:宇通cust_crm_guid"; } }
void UCCustomerAddOrEdit_SaveEvent(object sender, EventArgs e) //数据保存 { try { if (!CheckControlValue()) return; var sysSqlStrList = new List<SysSQLString>(); var custSql = BuildCustomerSqlString(); sysSqlStrList.Add(custSql.Item1); sysSqlStrList.AddRange(BuildContactRelation(custSql.Item2)); sysSqlStrList.AddRange(BuildVehicleRelation(custSql.Item2)); sysSqlStrList.AddRange(BuildVipMemberSqlString(custSql.Item2)); //ucAttr.GetAttachmentSql(sysSqlStrList); //保存附件时失败...目前保留此代码 var opName = wStatus == WindowStatus.Edit ? "更新客户档案" : "新增客户档案"; var result = DBHelper.BatchExeSQLStringMultiByTrans(opName, sysSqlStrList); if (result) { var customer = new tb_customer(); customer.cust_id = custSql.Item1.Param["cust_id"]; customer.cust_code = custSql.Item1.Param["cust_code"]; customer.cust_name = custSql.Item1.Param["cust_name"]; customer.cust_short_name = custSql.Item1.Param["cust_short_name"]; customer.cust_quick_code = custSql.Item1.Param["cust_quick_code"]; customer.cust_type = custSql.Item1.Param["cust_type"]; customer.legal_person = custSql.Item1.Param["legal_person"]; customer.enterprise_nature = custSql.Item1.Param["enterprise_nature"]; customer.cust_tel = custSql.Item1.Param["cust_tel"]; customer.cust_fax = custSql.Item1.Param["cust_fax"]; customer.cust_email = custSql.Item1.Param["cust_email"]; customer.cust_phone = custSql.Item1.Param["cust_phone"]; customer.cust_website = custSql.Item1.Param["cust_website"]; customer.province = custSql.Item1.Param["province"]; customer.city = custSql.Item1.Param["city"]; customer.county = custSql.Item1.Param["county"]; customer.cust_address = custSql.Item1.Param["cust_address"]; customer.zip_code = custSql.Item1.Param["zip_code"]; customer.tax_num = custSql.Item1.Param["tax_num"]; customer.indepen_legalperson = custSql.Item1.Param["indepen_legalperson"]; customer.credit_rating = custSql.Item1.Param["credit_rating"]; customer.credit_line = Convert.ToInt32(custSql.Item1.Param["credit_line"]); customer.credit_account_period = Convert.ToInt32(custSql.Item1.Param["credit_account_period"]); customer.price_type = custSql.Item1.Param["price_type"]; customer.billing_name = custSql.Item1.Param["billing_name"]; customer.billing_address = custSql.Item1.Param["billing_address"]; customer.billing_account = custSql.Item1.Param["billing_account"]; customer.open_bank = custSql.Item1.Param["open_bank"]; customer.bank_account = custSql.Item1.Param["bank_account"]; customer.bank_account_person = custSql.Item1.Param["bank_account_person"]; customer.cust_remark = custSql.Item1.Param["cust_remark"]; customer.is_member = custSql.Item1.Param["is_member"]; customer.member_number = custSql.Item1.Param["member_number"]; customer.member_class = custSql.Item1.Param["member_class"]; if(rdbis_member_y.Checked) customer.member_period_validity = Convert.ToInt64(custSql.Item1.Param["member_period_validity"]); customer.status = custSql.Item1.Param["status"]; customer.enable_flag = custSql.Item1.Param["enable_flag"]; customer.data_source = custSql.Item1.Param["data_source"]; customer.cust_crm_guid = custSql.Item1.Param["cust_crm_guid"]; customer.accessories_discount = 0; customer.workhours_discount = 0; customer.country = custSql.Item1.Param["country"]; customer.indepen_legalperson = custSql.Item1.Param["indepen_legalperson"]; customer.market_segment = custSql.Item1.Param["market_segment"]; customer.institution_code = custSql.Item1.Param["institution_code"]; customer.com_constitution = custSql.Item1.Param["com_constitution"]; customer.registered_capital = custSql.Item1.Param["registered_capital"]; customer.vehicle_structure = custSql.Item1.Param["vehicle_structure"]; customer.agency = custSql.Item1.Param["agency"]; customer.sap_code = custSql.Item1.Param["sap_code"]; customer.business_scope = custSql.Item1.Param["business_scope"]; customer.ent_qualification = custSql.Item1.Param["ent_qualification"]; if (wStatus == WindowStatus.Edit) { customer.update_by = custSql.Item1.Param["update_by"]; customer.update_time = Convert.ToInt64(custSql.Item1.Param["update_time"]); } else { customer.create_time = Convert.ToInt64(custSql.Item1.Param["create_time"]); customer.create_by = custSql.Item1.Param["create_by"]; } var flag = DBHelper.WebServHandler(opName, EnumWebServFunName.UpLoadCustomer, customer); if (String.IsNullOrEmpty(flag)) { var contactSql = BuildContactRelation(custSql.Item2).ToArray(); foreach (var sysSqlString in contactSql) { if (!sysSqlString.Param.ContainsKey("cont_id")) continue; var contId = sysSqlString.Param["cont_id"]; var dt1 = DBHelper.GetTable("获取客户CRMID", "tb_customer","*", String.Format("cust_id = '{0}'", customer.cust_id), "", ""); var dt = DBHelper.GetTable("根据客户档案获取联系信息", "v_contacts", string.Format("*,{0} phone", EncryptByDB.GetDesFieldValue("cont_phone")), " cont_id = '" + contId + "'", "", ""); if (dt.DefaultView != null && dt.DefaultView.Count > 0) { var cont = new tb_contacts_ex { cont_id = CommonCtrl.IsNullToString(dt.DefaultView[0]["cont_id"]), cont_name = CommonCtrl.IsNullToString(dt.DefaultView[0]["cont_name"]), cont_post = CommonCtrl.IsNullToString(dt.DefaultView[0]["cont_post_name"]), cont_phone = CommonCtrl.IsNullToString(dt.DefaultView[0]["phone"]), nation = CommonCtrl.IsNullToString(dt.DefaultView[0]["nation_name"]), parent_customer = CommonCtrl.IsNullToString(dt1.DefaultView[0]["cust_crm_guid"]), sex = CommonCtrl.IsNullToString(dt.DefaultView[0]["sex"]), status = CommonCtrl.IsNullToString(dt.DefaultView[0]["status"]), cont_post_remark = CommonCtrl.IsNullToString(dt.DefaultView[0]["post_remark"]), cont_crm_guid = CommonCtrl.IsNullToString(dt.DefaultView[0]["cont_crm_guid"]), contact_type = "01" //标识类型为联系人 }; var flag4Cont = DBHelper.WebServHandler(opName, EnumWebServFunName.UpLoadCcontact, cont); if (String.IsNullOrEmpty(flag4Cont)) { //do something } } } } MessageBoxEx.Show("保存成功!", "保存"); UCCustomerManager.BindPageData(); deleteMenuByTag(Tag.ToString(), UCCustomerManager.Name); } else { MessageBoxEx.Show("保存失败!", "保存"); } } catch (Exception ex) { MessageBoxEx.Show("保存失败!" + ex.Message, "提示"); } }