/// <summary> /// 获得数据列表 /// </summary> public List<DB_Talk.Model.m_Manager> DataTableToList(DataSet ds) { List<DB_Talk.Model.m_Manager> modelList = new List<DB_Talk.Model.m_Manager>(); if (ds == null) return modelList; DataTable dt = ds.Tables[0]; int rowsCount = dt.Rows.Count; if (rowsCount > 0) { DB_Talk.Model.m_Manager model; for (int n = 0; n < rowsCount; n++) { model = new DB_Talk.Model.m_Manager(); if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="") { model.ID=int.Parse(dt.Rows[n]["ID"].ToString()); } if(dt.Rows[n]["BoxID"]!=null && dt.Rows[n]["BoxID"].ToString()!="") { model.BoxID=int.Parse(dt.Rows[n]["BoxID"].ToString()); } if(dt.Rows[n]["vc_UserName"]!=null && dt.Rows[n]["vc_UserName"].ToString()!="") { model.vc_UserName= dt.Rows[n]["vc_UserName"].ToString(); } if(dt.Rows[n]["vc_Password"]!=null && dt.Rows[n]["vc_Password"].ToString()!="") { model.vc_Password= dt.Rows[n]["vc_Password"].ToString(); } if(dt.Rows[n]["LeftDispatchNumber"]!=null && dt.Rows[n]["LeftDispatchNumber"].ToString()!="") { model.LeftDispatchNumber=int.Parse(dt.Rows[n]["LeftDispatchNumber"].ToString()); } if(dt.Rows[n]["RightDispatchNumber"]!=null && dt.Rows[n]["RightDispatchNumber"].ToString()!="") { model.RightDispatchNumber=int.Parse(dt.Rows[n]["RightDispatchNumber"].ToString()); } if(dt.Rows[n]["LeftDispatchName"]!=null && dt.Rows[n]["LeftDispatchName"].ToString()!="") { model.LeftDispatchName= dt.Rows[n]["LeftDispatchName"].ToString(); } if(dt.Rows[n]["RightDispatchName"]!=null && dt.Rows[n]["RightDispatchName"].ToString()!="") { model.RightDispatchName= dt.Rows[n]["RightDispatchName"].ToString(); } if(dt.Rows[n]["i_Net"]!=null && dt.Rows[n]["i_Net"].ToString()!="") { model.i_Net=int.Parse(dt.Rows[n]["i_Net"].ToString()); } if(dt.Rows[n]["i_Operate"]!=null && dt.Rows[n]["i_Operate"].ToString()!="") { model.i_Operate=int.Parse(dt.Rows[n]["i_Operate"].ToString()); } if(dt.Rows[n]["i_Dispatch"]!=null && dt.Rows[n]["i_Dispatch"].ToString()!="") { model.i_Dispatch=int.Parse(dt.Rows[n]["i_Dispatch"].ToString()); } if(dt.Rows[n]["dt_CreateTime"]!=null && dt.Rows[n]["dt_CreateTime"].ToString()!="") { model.dt_CreateTime=DateTime.Parse(dt.Rows[n]["dt_CreateTime"].ToString()); } if(dt.Rows[n]["vc_Memo"]!=null && dt.Rows[n]["vc_Memo"].ToString()!="") { model.vc_Memo= dt.Rows[n]["vc_Memo"].ToString(); } if(dt.Rows[n]["i_Flag"]!=null && dt.Rows[n]["i_Flag"].ToString()!="") { model.i_Flag=int.Parse(dt.Rows[n]["i_Flag"].ToString()); } if(dt.Rows[n]["i_TellType"]!=null && dt.Rows[n]["i_TellType"].ToString()!="") { model.i_TellType=int.Parse(dt.Rows[n]["i_TellType"].ToString()); } if(dt.Rows[n]["i_IsDispatch"]!=null && dt.Rows[n]["i_IsDispatch"].ToString()!="") { model.i_IsDispatch=int.Parse(dt.Rows[n]["i_IsDispatch"].ToString()); } if(dt.Rows[n]["vc_BoxID"]!=null && dt.Rows[n]["vc_BoxID"].ToString()!="") { model.vc_BoxID= dt.Rows[n]["vc_BoxID"].ToString(); } modelList.Add(model); } } return modelList; }
private void btnOK_Click(object sender, EventArgs e) { if (txtUserName.Text.Trim() == "") { this.SendToBack(); CommControl.MessageBoxEx.MessageBoxEx.Show("用户名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtUserName.Focus(); return; } DB_Talk.BLL.m_Manager userBll = new DB_Talk.BLL.m_Manager(); if (userBll.GetModelList("i_Flag=0 and vc_UserName='******'").Count==0 && txtPassword.Text.Trim().ToUpper() == "ADMIN" && txtUserName.Text.Trim().ToUpper() == "ADMIN") { DB_Talk.Model.m_Manager model = new DB_Talk.Model.m_Manager(); model.vc_UserName = "******"; model.vc_Password = "******"; model.i_Net = 1; model.i_Dispatch = 1; model.i_Operate = 1; userBll.Add(model); Global.Params.UserID = -1; Global.Params.UserName = "******"; Global.Params.Password = "******"; SaveLoginUser(txtUserName.Text.Trim()); m_IsOK = true; this.Hide(); return; } else { //验证次数 m_ValidateCount++; //DB_Talk.BLL.m_Manager userBll = new DB_Talk.BLL.m_Manager(); List<DB_Talk.Model.m_Manager> userList = userBll.GetModelList(" i_flag = 0 and vc_UserName='******'", "''") + "'"); if (userList != null && userList.Count > 0) { Global.Params.UserID = userList[0].ID; Global.Params.UserName = userList[0].vc_UserName; string password = userList[0].vc_Password; if (password == null) password = ""; if (password == txtPassword.Text.Trim()) { if (Convert.ToBoolean(userList[0].i_Net) == true) { Global.Params.Password = password; SaveLoginUser(txtUserName.Text.Trim()); //系统用户控制可以登录的box //string strW = ""; //if (userList[0].vc_BoxID != null && userList[0].vc_BoxID != "") // strW = " i_Flag=0 and ID in(" + userList[0].vc_BoxID + ")"; //添加到系统里面的box就可以登录 string strW = " i_Flag=0 "; if (strW == "") Global.Params.LstBox = new List<DB_Talk.Model.m_Box>(); //为空时 全部不选 else Global.Params.LstBox = new DB_Talk.BLL.m_Box().GetModelList(strW); m_IsOK = true; this.Hide(); return; } else { this.SendToBack(); CommControl.MessageBoxEx.MessageBoxEx.Show("用户无网络管理权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { this.SendToBack(); CommControl.MessageBoxEx.MessageBoxEx.Show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { this.SendToBack(); CommControl.MessageBoxEx.MessageBoxEx.Show("用户名不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } if (m_ValidateCount >= 3) { m_IsOK = false; this.Hide(); return; } return; }
/// <summary> /// 根据条件得到一个对象实体 /// </summary> public DB_Talk.Model.m_Manager GetModel(string strWhere) { StringBuilder strSql=new StringBuilder(); strSql.Append(" select top 1 "); strSql.Append(" ID, BoxID, vc_UserName, vc_Password, LeftDispatchNumber, RightDispatchNumber, LeftDispatchName, RightDispatchName, i_Net, i_Operate, i_Dispatch, dt_CreateTime, vc_Memo, i_Flag, i_TellType, i_IsDispatch, vc_BoxID "); strSql.Append(" from m_Manager "); if(strWhere.Trim()!="") { strSql.Append(" where "+strWhere); } DB_Talk.Model.m_Manager model=new DB_Talk.Model.m_Manager(); DataSet ds=GetDataSet(strSql.ToString()); if(ds!=null && ds.Tables[0].Rows.Count>0) { model=DataTableToList(ds)[0]; return model; } else { return null; } }