public static bool InsertSDepartment(SDepartment department) { MySqlConnection con = DBTools.GetMySqlConnection(); MySqlCommand cmd; int count = -1; // 受影响行数 try { con.Open(); cmd = con.CreateCommand(); cmd.CommandText = INSERT_SDEPARTMENT_STR; cmd.Parameters.AddWithValue("@Name", department.Name); // 部门职位 cmd.Parameters.AddWithValue("@ShortCall", department.ShortCall); // 部门简称 cmd.Parameters.AddWithValue("@CanBoundary", department.CanBoundary); cmd.Parameters.AddWithValue("@CanInland", department.CanInland); cmd.Parameters.AddWithValue("@CanEmergency", department.CanEmergency); cmd.Parameters.AddWithValue("@CanRegular", department.CanRegular); count = cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); con.Dispose(); if (count == 1) // 插入成功后的受影响行数为1 { Console.WriteLine("部门详细插入成功"); return true; } else { Console.WriteLine("部门详细插入失败"); return false; } } catch (Exception) { throw; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } }
public static bool ModifySDepartment(SDepartment department) { MySqlConnection con = DBTools.GetMySqlConnection(); MySqlCommand cmd; int count = -1; try { con.Open(); cmd = con.CreateCommand(); cmd.CommandText = MODIFY_SDEPARTMENT_ID_STR; cmd.Parameters.AddWithValue("@Id", department.Id); cmd.Parameters.AddWithValue("@Name", department.Name); // 员工姓名 cmd.Parameters.AddWithValue("@ShortCall", department.ShortCall); // 部门简称 cmd.Parameters.AddWithValue("@CanBoundary", department.CanBoundary); cmd.Parameters.AddWithValue("@CanInland", department.CanInland); cmd.Parameters.AddWithValue("@CanEmergency", department.CanEmergency); cmd.Parameters.AddWithValue("@CanRegular", department.CanRegular); count = cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); con.Dispose(); if (count == 1) { Console.WriteLine("修改部门信息" + department.Id.ToString() + "成功"); return true; } else { Console.WriteLine("修改部门名称" + department.Id.ToString() + "失败"); return false; } } catch (Exception) { throw; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } }
public static bool SetSDepartmentRegular(SDepartment department) { MySqlConnection con = DBTools.GetMySqlConnection(); MySqlCommand cmd; int count; try { con.Open(); cmd = con.CreateCommand(); cmd.CommandText = SET_SDEPARTMENT_REGULAR_STR; cmd.Parameters.AddWithValue("@CanRegular", department.CanRegular); count = cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); con.Dispose(); if (count == 1) // 插入成功后的受影响行数为1 { Console.WriteLine("修改部门的界河项目权限成功"); return true; } else { Console.WriteLine("修改部门的界河项目权限失败"); return false; } } catch (Exception) { throw; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } }
public static List<SDepartment> QuerySDepartment() { MySqlConnection con = DBTools.GetMySqlConnection(); MySqlCommand cmd; List<SDepartment> departments = new List<SDepartment>(); try { con.Open(); cmd = con.CreateCommand(); cmd.CommandText = QUERY_SDEPARTMENT_STR; MySqlDataReader sqlRead = cmd.ExecuteReader(); cmd.Dispose(); while (sqlRead.Read()) { SDepartment department = new SDepartment(); department.Id = int.Parse(sqlRead["id"].ToString()); department.Name = sqlRead["name"].ToString(); department.ShortCall = sqlRead["shortcall"].ToString(); department.CanBoundary = int.Parse(sqlRead["canboundary"].ToString()); department.CanInland = int.Parse(sqlRead["caninland"].ToString()); department.CanEmergency = int.Parse(sqlRead["canemergency"].ToString()); department.CanRegular = int.Parse(sqlRead["canregular"].ToString()); departments.Add(department); } con.Close(); con.Dispose(); } catch (Exception) { throw; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } return departments; }