public string Add(ClientViewModel model) { #if DEBUG SysConfig.CurrentUser = UserModel.SingleOrDefault("3"); #endif if (ModelState.IsValid) { ClientModel client = new ClientModel(); client.No = CommonMethod.GetLatestSerialNo(SysConfig.SerialNo.ClientNo); //客户编号 client.Type = model.Type; //客户类别 client.ChName = model.ChName; //中文名称 client.EnName = model.EnName; //英文名称 client.ShortName = model.ShortName; //简称 client.Countryid = model.Countryid.ToInt(); //国家 client.Address = model.Address; //地址 client.Phone = model.Phone; //电话 client.Email = model.Email; //邮箱 client.Linkman = model.Linkman; //联系人 client.Remark = model.Remark; //备注 client.BelongsMan = CommonMethod.GetBelongsMan( //业务员 SysConfig.CurrentUser.Departmentid.ToString()); client.BelongsDepartment = CommonMethod.GetBelongsDepartment( //所属部门 SysConfig.CurrentUser.Departmentid.ToString()); ApprovalRuleModel rule = ApprovalRuleModel.FirstOrDefault(@"where Del_Flag = 0 and Doc_Type = 1 and DepartmentID = @0", client.BelongsDepartment); //如果没有审批规则 则直接生效 if (rule == null) { client.ApprovalStatus = "4"; //审批状态 4:已生效 } //如果有审批规则 则待提交 else { client.ApprovalStatus = "1"; //审批状态 1:待提交 } client.DelFlag = 0; //有效状态 client.CreateMan = SysConfig.CurrentUser.Id; //制单人 client.CreateTime = DateTime.Now; //制单时间 int result = client.Insert().ToInt(); if (result > 0) { //更新客户最大序列号 CommonMethod.UpdateSerialNo(SysConfig.SerialNo.ClientNo); //记录操作日志 CommonMethod.Log(SysConfig.CurrentUser.Id, "Insert", "Sys_Client"); CommonMethod.Log(SysConfig.CurrentUser.Id, "Update", "Sys_SerialNo"); return "1"; } } return "0"; }