private void CreateRoute(string name, int organizecity) { VST_RouteBLL routebll = new VST_RouteBLL(); routebll.Model.Code = "R" + ViewState["ID"].ToString(); routebll.Model.Name = "线路-" + name; routebll.Model.RelateStaff = (int)ViewState["ID"]; routebll.Model.OrganizeCity = organizecity; routebll.Model.OwnerClient = (int)Session["OwnerClient"]; routebll.Model.OwnerType = (int)Session["OwnerType"]; routebll.Model.ApproveFlag = 1; routebll.Model.EnableFlag = "Y"; routebll.Model.InsertStaff = (int)Session["UserID"]; routebll.Add(); }
/// <summary> /// 导入员工资料 /// </summary> /// <param name="TemplateID"></param> /// <param name="Staff"></param> /// <param name="StaffSheet"></param> /// <param name="State">3:成功 4:失败 5:部分成功</param> /// <returns></returns> //public string DoImportStaff(int TemplateID, int Client, ISheet StaffSheet, out int State) public string DoImportStaff(int TemplateID, int Client, ISheet Sheet, out int State) { string ImportInfo = "【员工资料】Excel表:"; State = 0; IPT_UploadTemplateBLL _template = new IPT_UploadTemplateBLL(TemplateID); List<string> listPDT = new List<string>() { "序号", "姓名", "职务", "手机号码", "关联车号", "身份证号" }; DataTable dt = null; bool flag = VertifySheet(Sheet, listPDT, out dt, ref ImportInfo); if (!flag) { State = 4; return ImportInfo; } foreach (DataRow dr in dt.Rows)//循环导入数据 { try { string _staffName = dr["姓名"].ToString(); IList<Org_Staff> _listStaff = Org_StaffBLL.GetStaffList(" Dimission=1 AND OwnerClient=" + _template.Model.ClientID.ToString() + " AND RealName='" + _staffName + "'"); if (_listStaff != null && _listStaff.Count > 0) { ImportInfo += string.Format("导入序列号为{0},名字为{1}的数据行时与现有员工名字重复,跳过此行\r\n", dr["序号"].ToString(), _staffName); continue; } int _staffPosition = 0; string _strStaffPosition = dr["职务"].ToString(); string _staffPhone = dr["手机号码"].ToString(); string _staffIDCode = dr["身份证号"].ToString(); if (!string.IsNullOrEmpty(_strStaffPosition))//无职位默认为业代 { IList<Org_Position> _listPosition = Org_PositionBLL.GetModelList(" Name='" + _strStaffPosition + "'"); if (_listPosition != null && _listPosition.Count > 0) _staffPosition = _listPosition[0].ID; } else { _staffPosition = 1030; } Org_StaffBLL _bllStaff = new Org_StaffBLL(); CM_ClientBLL c = new CM_ClientBLL(_template.Model.ClientID); CM_ClientManufactInfo manufactinfo = c.GetManufactInfo(); if (c != null && manufactinfo != null) { _bllStaff.Model.OrganizeCity = manufactinfo.OrganizeCity; _bllStaff.Model.OfficialCity = c.Model.OfficialCity; } _bllStaff.Model.RealName = _staffName; _bllStaff.Model.Position = _staffPosition; _bllStaff.Model.Mobile = _staffPhone; _bllStaff.Model.TeleNum = _staffPhone; _bllStaff.Model.IDCode = _staffIDCode; _bllStaff.Model.InsertStaff = _template.Model.InsertStaff; _bllStaff.Model.OwnerClient = _template.Model.ClientID; _bllStaff.Model.OwnerType = 3; _bllStaff.Model.Dimission = 1; _bllStaff.Model.ApproveFlag = 1; int _ClientID = _bllStaff.Add();//当前员工ID //创建默认员工线路 if (_ClientID > 0) { if (_bllStaff.Model.Position == 1030)//业待创建默认路线 { VST_RouteBLL routebll = new VST_RouteBLL(); routebll.Model.Code = "R" + _ClientID.ToString(); routebll.Model.Name = "线路-" + _bllStaff.Model.RealName; routebll.Model.RelateStaff = _ClientID; routebll.Model.OrganizeCity = _bllStaff.Model.OrganizeCity; routebll.Model.OwnerClient = _template.Model.ClientID; routebll.Model.OwnerType = 3; routebll.Model.ApproveFlag = 1; routebll.Model.EnableFlag = "Y"; routebll.Model.InsertStaff = _template.Model.InsertStaff; routebll.Add(); } if (_bllStaff.Model.Position == 1030 || _bllStaff.Model.Position == 1050)//只有业待和司机能关联车号 { #region 获取车号ID int _staffCar = 0; string _strStaffCar = dr["关联车号"].ToString(); if (!string.IsNullOrEmpty(_strStaffCar)) { IList<CM_Vehicle> _listVehicles = CM_VehicleBLL.GetModelList("Client=" + _template.Model.ClientID + " AND VehicleNo='" + _strStaffPosition + "' "); if (_listVehicles != null && _listVehicles.Count > 0) _staffCar = _listVehicles[0].ID; else { CM_VehicleBLL vehicle = new CM_VehicleBLL(); vehicle.Model.Client = _template.Model.ClientID; vehicle.Model.VehicleNo = _strStaffCar; vehicle.Model.State = 1; vehicle.Model.Remark = "新导入未确认"; vehicle.Model.VehicleClassify = 2; _staffCar = vehicle.Add(); } } #endregion if (_staffCar > 0)//关联车号 { IList<CM_VehicleInStaff> _listVehicleInStaff = CM_VehicleInStaffBLL.GetModelList("Vehicle=" + _staffCar.ToString() + " AND Staff=" + _ClientID.ToString()); if (_listVehicleInStaff == null || _listVehicleInStaff.Count == 0) { CM_VehicleInStaffBLL vehicle_staff = new CM_VehicleInStaffBLL(); vehicle_staff.Model.Staff = _ClientID; vehicle_staff.Model.Vehicle = _staffCar; vehicle_staff.Model.InsertStaff = _template.Model.InsertStaff; vehicle_staff.Add(); } } } } } catch (Exception ex) { ImportInfo += "导入序列号为" + dr["序号"].ToString() + "的数据行时出现错误,错误说明:" + ex.Message + "\r\n"; State = 5; continue; } } if (State == 0) State = 3; ImportInfo += (State == 3 ? "导入完成!\r\n" : ""); IPT_UploadTemplateMessageBLL _bllUploadTemplateMessage = new IPT_UploadTemplateMessageBLL(); _bllUploadTemplateMessage.Model.TemplateID = TemplateID; _bllUploadTemplateMessage.Model.MessageType = State; _bllUploadTemplateMessage.Model.Content = ImportInfo; _bllUploadTemplateMessage.Add(); return ImportInfo; }
/** *返回状态 3:成功 4:失败 5:部分成功 */ #region 1.导入员工资料,废弃不用 /// <summary> /// 导入员工资料 /// </summary> /// <param name="TemplateID"></param> /// <param name="Staff"></param> /// <param name="StaffSheet"></param> /// <param name="State">3:成功 4:失败 5:部分成功</param> /// <returns></returns> //public string DoImportStaff(int TemplateID, int Client, ISheet StaffSheet, out int State) public string DoImportStaff(int TemplateID, int Client, ISheet Sheet, out int State) { string ImportInfo = "【员工资料】Excel表:"; State = 0; IPT_UploadTemplateBLL _template = new IPT_UploadTemplateBLL(TemplateID); List <string> listPDT = new List <string>() { "序号", "姓名", "职务", "手机号码", "关联车号", "身份证号" }; DataTable dt = null; bool flag = VertifySheet(Sheet, listPDT, out dt, ref ImportInfo); if (!flag) { State = 4; return(ImportInfo); } foreach (DataRow dr in dt.Rows)//循环导入数据 { try { string _staffName = dr["姓名"].ToString(); IList <Org_Staff> _listStaff = Org_StaffBLL.GetStaffList(" Dimission=1 AND OwnerClient=" + _template.Model.ClientID.ToString() + " AND RealName='" + _staffName + "'"); if (_listStaff != null && _listStaff.Count > 0) { ImportInfo += string.Format("导入序列号为{0},名字为{1}的数据行时与现有员工名字重复,跳过此行\r\n", dr["序号"].ToString(), _staffName); continue; } int _staffPosition = 0; string _strStaffPosition = dr["职务"].ToString(); string _staffPhone = dr["手机号码"].ToString(); string _staffIDCode = dr["身份证号"].ToString(); if (!string.IsNullOrEmpty(_strStaffPosition))//无职位默认为业代 { IList <Org_Position> _listPosition = Org_PositionBLL.GetModelList(" Name='" + _strStaffPosition + "'"); if (_listPosition != null && _listPosition.Count > 0) { _staffPosition = _listPosition[0].ID; } } else { _staffPosition = 1030; } Org_StaffBLL _bllStaff = new Org_StaffBLL(); CM_ClientBLL c = new CM_ClientBLL(_template.Model.ClientID); CM_ClientManufactInfo manufactinfo = c.GetManufactInfo(); if (c != null && manufactinfo != null) { _bllStaff.Model.OrganizeCity = manufactinfo.OrganizeCity; _bllStaff.Model.OfficialCity = c.Model.OfficialCity; } _bllStaff.Model.RealName = _staffName; _bllStaff.Model.Position = _staffPosition; _bllStaff.Model.Mobile = _staffPhone; _bllStaff.Model.TeleNum = _staffPhone; _bllStaff.Model.IDCode = _staffIDCode; _bllStaff.Model.InsertStaff = _template.Model.InsertStaff; _bllStaff.Model.OwnerClient = _template.Model.ClientID; _bllStaff.Model.OwnerType = 3; _bllStaff.Model.Dimission = 1; _bllStaff.Model.ApproveFlag = 1; int _ClientID = _bllStaff.Add();//当前员工ID //创建默认员工线路 if (_ClientID > 0) { if (_bllStaff.Model.Position == 1030)//业待创建默认路线 { VST_RouteBLL routebll = new VST_RouteBLL(); routebll.Model.Code = "R" + _ClientID.ToString(); routebll.Model.Name = "线路-" + _bllStaff.Model.RealName; routebll.Model.RelateStaff = _ClientID; routebll.Model.OrganizeCity = _bllStaff.Model.OrganizeCity; routebll.Model.OwnerClient = _template.Model.ClientID; routebll.Model.OwnerType = 3; routebll.Model.ApproveFlag = 1; routebll.Model.EnableFlag = "Y"; routebll.Model.InsertStaff = _template.Model.InsertStaff; routebll.Add(); } if (_bllStaff.Model.Position == 1030 || _bllStaff.Model.Position == 1050)//只有业待和司机能关联车号 { #region 获取车号ID int _staffCar = 0; string _strStaffCar = dr["关联车号"].ToString(); if (!string.IsNullOrEmpty(_strStaffCar)) { IList <CM_Vehicle> _listVehicles = CM_VehicleBLL.GetModelList("Client=" + _template.Model.ClientID + " AND VehicleNo='" + _strStaffPosition + "' "); if (_listVehicles != null && _listVehicles.Count > 0) { _staffCar = _listVehicles[0].ID; } else { CM_VehicleBLL vehicle = new CM_VehicleBLL(); vehicle.Model.Client = _template.Model.ClientID; vehicle.Model.VehicleNo = _strStaffCar; vehicle.Model.State = 1; vehicle.Model.Remark = "新导入未确认"; vehicle.Model.VehicleClassify = 2; _staffCar = vehicle.Add(); } } #endregion if (_staffCar > 0)//关联车号 { IList <CM_VehicleInStaff> _listVehicleInStaff = CM_VehicleInStaffBLL.GetModelList("Vehicle=" + _staffCar.ToString() + " AND Staff=" + _ClientID.ToString()); if (_listVehicleInStaff == null || _listVehicleInStaff.Count == 0) { CM_VehicleInStaffBLL vehicle_staff = new CM_VehicleInStaffBLL(); vehicle_staff.Model.Staff = _ClientID; vehicle_staff.Model.Vehicle = _staffCar; vehicle_staff.Model.InsertStaff = _template.Model.InsertStaff; vehicle_staff.Add(); } } } } } catch (Exception ex) { ImportInfo += "导入序列号为" + dr["序号"].ToString() + "的数据行时出现错误,错误说明:" + ex.Message + "\r\n"; State = 5; continue; } } if (State == 0) { State = 3; } ImportInfo += (State == 3 ? "导入完成!\r\n" : ""); IPT_UploadTemplateMessageBLL _bllUploadTemplateMessage = new IPT_UploadTemplateMessageBLL(); _bllUploadTemplateMessage.Model.TemplateID = TemplateID; _bllUploadTemplateMessage.Model.MessageType = State; _bllUploadTemplateMessage.Model.Content = ImportInfo; _bllUploadTemplateMessage.Add(); return(ImportInfo); }