/// <summary> /// get the principal data of a branch /// </summary> /// <param name="branch_id"></param> /// <param name="type"></param> /// <returns></returns> public object[] GetPrincipalOrViceDataFromBranchID(string branch_id, PrincipalOrVice type) { object[] result = new object[3]; string tempType = ""; if (type == PrincipalOrVice.Principal) { tempType = "principal"; } else { tempType = "vice_principal"; } string sql = "SELECT * from " + tempType + " WHERE " + tempType + ".branch_id = '" + branch_id + "'"; MySqlCommand command = new MySqlCommand(sql, conn); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { result[0] = reader.GetDateTime("date"); result[1] = reader.GetString("agent_id"); result[2] = reader.GetString("branch_id"); } reader.Close(); return(result); }
/// <summary> /// updating principal or vice principal data /// </summary> /// <param name="data"></param> /// <param name="type"></param> public void UpdatePrincipalOrVice(object[] data, PrincipalOrVice type) { string tempType = ""; if (type == PrincipalOrVice.Principal) { tempType = "principal"; } else { tempType = "vice_principal"; } string sql = "UPDATE " + tempType + " SET agent_id = @agentId WHERE branch_id = @branchId"; MySqlCommand command = new MySqlCommand(sql, conn); command.Parameters.Add(new MySqlParameter("@agentId", MySqlDbType.String)).Value = data[1]; command.Parameters.Add(new MySqlParameter("@branchId", MySqlDbType.String)).Value = data[2]; command.Prepare(); command.ExecuteNonQuery(); MessageBox.Show(tempType + " updated"); }
/// <summary> /// get principal or vice principal name /// </summary> /// <param name="type"></param> /// <returns></returns> public string[] GetPrincipalOrViceNames(PrincipalOrVice type) { List <string> result = new List <string>(); string tempType = ""; if (type == PrincipalOrVice.Principal) { tempType = "principal"; } else { tempType = "vice_principal"; } string sql = "SELECT " + tempType + ".agent_id from " + tempType + " where " + tempType + ".agent_status = 1 or agent.agent_id = '_parent'"; MySqlCommand command = new MySqlCommand(sql, conn); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { result.Add(reader.GetString("agent_name")); } reader.Close(); return(result.ToArray());; }
/// <summary> /// insert principal or vice principal /// </summary> /// <param name="data"></param> /// <param name="type"></param> public void InsertPrincipalOrVice(object[] data, PrincipalOrVice type) { string tempType = ""; if (type == PrincipalOrVice.Principal) { tempType = "principal"; } else { tempType = "vice_principal"; } string sql = "INSERT INTO " + tempType + " (date, agent_id, branch_id) VALUES(@date, @agentId, @branchId)"; MySqlCommand command = new MySqlCommand(sql, conn); command.Parameters.Add(new MySqlParameter("@date", MySqlDbType.Date)).Value = data[0]; command.Parameters.Add(new MySqlParameter("@agentId", MySqlDbType.String)).Value = data[1]; command.Parameters.Add(new MySqlParameter("@branchId", MySqlDbType.String)).Value = data[2]; command.Prepare(); command.ExecuteNonQuery(); }
/// <summary> /// fill the principal or vice data /// </summary> /// <param name="tabPage"></param> /// <param name="branchName"></param> /// <param name="type"></param> void FillPrincipalOrViceData(ref MetroTabPage tabPage, string branchName, PrincipalOrVice type) { PrincipalAndVice tempData; tempData = new PrincipalAndVice(Connection.Instance.GetPrincipalOrViceDataFromBranchID(Connection.Instance.GetBranchIDFromName(branchName), type)); if (type == PrincipalOrVice.Principal) { comboBoxPrincipalName.GetComboBoxAutoFillData(Connection.Instance.GetAgentNamesInBranch(Connection.Instance.GetBranchIDFromName(comboBoxPrincipalBranchName.Text))); } else { comboBoxVicePrincipalName.GetComboBoxAutoFillData(Connection.Instance.GetAgentNamesInBranch(Connection.Instance.GetBranchIDFromName(comboBoxVicePrincipalBranchName.Text))); } AutoFillPrincipalOrViceData(ref tabPage, tempData); }